public final class GeometryTools2D
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static double |
THRESHOLD
The threshold for equality testing in geometric operations.
|
Modifier and Type | Method and Description |
---|---|
static Line2D |
clipToRectangle(Line2D line,
double xMin,
double yMin,
double xMax,
double yMax)
Clip a line to a rectangle.
|
static double |
computeArea(java.util.List<Point2D> vertices)
Compute the area of a simple polygon.
|
static Point2D |
computeCentroid(java.util.List<Point2D> vertices)
Compute the centroid of a simple polygon.
|
static boolean |
contains(Line2D line,
Point2D point)
Find out if a point is on a line.
|
static double |
getAngleBetweenVectors(Vector2D first,
Vector2D second)
Compute the angle between two vectors in degrees.
|
static Point2D |
getClosestPoint(Line2D line,
Point2D point)
Find the closest point on a line.
|
static Point2D |
getClosestPointOnSegment(Line2D line,
Point2D point)
Find the closest point on a line.
|
static double |
getDistance(Point2D p1,
Point2D p2)
Compute the distance between two points.
|
static Point2D |
getIntersectionPoint(Line2D l1,
Line2D l2)
Find the intersection point of two lines.
|
static double |
getLeftAngleBetweenLines(Line2D first,
Line2D second)
Compute the angle between two lines in a counter-clockwise direction.
|
static double |
getLeftAngleBetweenVectors(Vector2D first,
Vector2D second)
Compute the angle between two vectors in a counter-clockwise direction.
|
static double |
getRightAngleBetweenLines(Line2D first,
Line2D second)
Compute the angle between two lines in a clockwise direction.
|
static double |
getRightAngleBetweenVectors(Vector2D first,
Vector2D second)
Compute the angle between two vectors in a clockwise direction.
|
static Point2D |
getSegmentIntersectionPoint(Line2D l1,
Line2D l2)
Find the intersection point of two line segments.
|
static boolean |
isRightTurn(Line2D first,
Line2D second)
Find out if we turn right from one line to another.
|
static boolean |
isRightTurn(Vector2D first,
Vector2D second)
Find out if we turn right from one vector to another.
|
static boolean |
nearlyZero(double d)
Find out if a number is near enough to zero.
|
static boolean |
parallel(Line2D l1,
Line2D l2)
Are two lines parallel?
|
static java.util.List<Line2D> |
pointsToLines(java.util.List<Point2D> points)
Convert a list of Point2D objects to a list of lines connecting adjacent points.
|
static java.util.List<Line2D> |
pointsToLines(java.util.List<Point2D> points,
boolean close)
Convert a list of Point2D objects to a list of lines connecting adjacent points.
|
static double |
positionOnLine(Line2D line,
Point2D point)
Find out how far a point is along a line.
|
static java.util.List<Point2D> |
vertexArrayToPoints(double[] vertices)
Convert a vertex array to a list of Point2D objects.
|
static java.util.List<Point2D> |
vertexArrayToPoints(int[] vertices)
Convert a vertex array to a list of Point2D objects.
|
public static final double THRESHOLD
public static Point2D getIntersectionPoint(Line2D l1, Line2D l2)
l1
- The first line.l2
- The second line.public static Point2D getSegmentIntersectionPoint(Line2D l1, Line2D l2)
l1
- The first line segment.l2
- The second line segment.public static boolean parallel(Line2D l1, Line2D l2)
l1
- The first line.l2
- The second line.public static boolean contains(Line2D line, Point2D point)
line
- The line to test.point
- The point to test.public static double positionOnLine(Line2D line, Point2D point)
line
- The line to test.point
- The point to test.public static double getRightAngleBetweenLines(Line2D first, Line2D second)
first
- The first line.second
- The second line.public static double getLeftAngleBetweenLines(Line2D first, Line2D second)
first
- The first line.second
- The second line.public static double getAngleBetweenVectors(Vector2D first, Vector2D second)
first
- The first vector.second
- The second vector.public static double getRightAngleBetweenVectors(Vector2D first, Vector2D second)
first
- The first vector.second
- The second vector.public static double getLeftAngleBetweenVectors(Vector2D first, Vector2D second)
first
- The first vector.second
- The second vector.public static boolean isRightTurn(Line2D first, Line2D second)
first
- The first line.second
- The second line.public static boolean isRightTurn(Vector2D first, Vector2D second)
first
- The first vector.second
- The second vector.public static boolean nearlyZero(double d)
d
- The number to test.public static double computeArea(java.util.List<Point2D> vertices)
vertices
- The vertices of the polygon.public static Point2D computeCentroid(java.util.List<Point2D> vertices)
vertices
- The vertices of the polygon.public static java.util.List<Point2D> vertexArrayToPoints(int[] vertices)
vertices
- The vertices in x, y order.public static java.util.List<Point2D> vertexArrayToPoints(double[] vertices)
vertices
- The vertices in x, y order.public static java.util.List<Line2D> pointsToLines(java.util.List<Point2D> points)
points
- The points to connect.public static java.util.List<Line2D> pointsToLines(java.util.List<Point2D> points, boolean close)
points
- The points to connect.close
- Whether to close the shape or not.public static Point2D getClosestPoint(Line2D line, Point2D point)
line
- The line to check.point
- The point to check against.public static Point2D getClosestPointOnSegment(Line2D line, Point2D point)
line
- The line to check.point
- The point to check against.public static double getDistance(Point2D p1, Point2D p2)
p1
- The first point.p2
- The second point.public static Line2D clipToRectangle(Line2D line, double xMin, double yMin, double xMax, double yMax)
line
- The line to clip.xMin
- The lower X coordinate of the rectangle.yMin
- The lower Y coordinate of the rectangle.xMax
- The upper X coordinate of the rectangle.yMax
- The upper Y coordinate of the rectangle.