public final class Geom extends Object
Modifier and Type | Method and Description |
---|---|
static YList |
calcConvexHull(YList points)
Calculates the convex hull for a set of points.
|
static YPoint |
calcIntersection(double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4)
Calculates the intersection point of two affine lines.
|
static Rectangle2D |
calcIntersection(Rectangle2D r1,
Rectangle2D r2,
Rectangle2D dest)
Intersects the pair of specified source
Rectangle2D objects and puts the result into the specified destination Rectangle2D
object. |
static YPoint |
calcIntersection(YPoint p1,
YPoint p2,
YPoint p3,
YPoint p4)
Calculates the intersection point of two affine lines.
|
static YPoint |
calcIntersection(YPoint p1,
YVector d1,
YPoint p2,
YVector d2)
Calculates the intersection point of two affine lines.
|
static Rectangle2D |
calcUnion(Rectangle2D r1,
Rectangle2D r2,
Rectangle2D dest)
Unions the pair of source
Rectangle2D objects and puts the result into the specified destination Rectangle2D
object. |
static boolean |
collinear(YPoint p,
YPoint q,
YPoint r)
Returns
true iff the given points are collinear, i.e. |
static double |
distanceToLineSegment(double pointX,
double pointY,
double lineX1,
double lineY1,
double lineX2,
double lineY2)
Determines the distance of the point
p to the line segment [l1, l2] . |
static boolean |
leftTurn(YPoint p,
YPoint q,
YPoint r)
Same as
orientation(p,q,r) > 0 . |
static boolean |
linesIntersect(double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4)
Returns whether the two lines defined by the given coordinates intersect or not.
|
static int |
orientation(double px,
double py,
double qx,
double qy,
double rx,
double ry)
Same as
orientation(YPoint, YPoint, YPoint) with double values as arguments. |
static int |
orientation(YPoint p,
YPoint q,
YPoint r)
Returns the orientation of point
r relative to the directed line from point p to point q . |
static YPoint |
projection(double pointX,
double pointY,
double lineX1,
double lineY1,
double lineX2,
double lineY2)
Determines the projection of the point
p onto the line segment [l1, l2] . |
static boolean |
rightTurn(YPoint p,
YPoint q,
YPoint r)
Same as
orientation(p,q,r) < 0 . |
static int |
sideOfCircle(YPoint a,
YPoint b,
YPoint c,
YPoint d)
Returns +1 if point
d lies left of the directed circle through points a , b , and c , 0 if
a,b,c and d are cocircular, and -1 otherwise. |
static double |
toDegrees(double angrad)
Converts the given degree value from radian to angular.
|
static double |
toRadians(double angdeg)
Converts the given degree value from angular to radian.
|
public static final YList calcConvexHull(YList points)
O(n)*log(n), n := points.size()
points
- a list of YPoint
objectsYPoint
objects that constitute the convex hull of the given points. The list contains points in
counter clockwise order around the hull. The first point is the one with the smallest x
coordinate. If two such
points exist then of these points the one with the smallest y
coordinate is chosen as the first one.public static final YPoint calcIntersection(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
Each line is given by the coordinates of two points.
x1
- x-coordinate of one point on the first line.y1
- y-coordinate of one point on the first line.x2
- x-coordinate of another point on the first line.y2
- y-coordinate of another point on the first line.x3
- x-coordinate of one point on the second line.y3
- y-coordinate of one point on the second line.x4
- x-coordinate of another point on the second line.y4
- y-coordinate of another point on the second line.null
if there is no intersection.public static final Rectangle2D calcIntersection(Rectangle2D r1, Rectangle2D r2, Rectangle2D dest)
Rectangle2D
objects and puts the result into the specified destination Rectangle2D
object.
If one or both of the source rectangles have negative width or height, the resulting rectangle will be located at (0,0) with a width and height of -1. One of the source rectangles can also be the destination to avoid creating a third Rectangle2D object, but in this case the original points of this source rectangle will be overwritten by this method.
r1
- the first of a pair of Rectangle2D
objects to be intersected with each otherr2
- the second of a pair of Rectangle2D
objects to be intersected with each otherdest
- the Rectangle2D
that holds the results of the intersection of r1
and r2
public static final YPoint calcIntersection(YPoint p1, YPoint p2, YPoint p3, YPoint p4)
Each line is given by two points.
p1
- one point on the first line.p2
- another point on the first line.p3
- one point on the second line.p4
- another point on the second line.null
if there is no intersection.public static final YPoint calcIntersection(YPoint p1, YVector d1, YPoint p2, YVector d2)
Each line is given by a point and a direction vector.
p1
- origin point of the first line.d1
- direction vector of the first line.p2
- origin point of the second line.d2
- direction vector of the second line.null
if there is no intersection.public static final Rectangle2D calcUnion(Rectangle2D r1, Rectangle2D r2, Rectangle2D dest)
Rectangle2D
objects and puts the result into the specified destination Rectangle2D
object.
If one of the source rectangles has negative width or height, it is excluded from the union. If both source rectangles
have negative width or height, the destination rectangle will become a copy of r1
. One of the source rectangles
can also be the destination to avoid creating a third Rectangle2D object, but in this case the original points of this
source rectangle will be overwritten by this method. If the destination is null
, a new Rectangle2D
is
created.
r1
- the first of a pair of Rectangle2D
objects to be combined with each otherr2
- the second of a pair of Rectangle2D
objects to be combined with each otherdest
- the Rectangle2D
that holds the results of the union of r1
and r2
public static final boolean collinear(YPoint p, YPoint q, YPoint r)
true
iff the given points are collinear, i.e.
all three points lie on a common line.
Same as orientation(p,q,r) == 0
public static final double distanceToLineSegment(double pointX, double pointY, double lineX1, double lineY1, double lineX2, double lineY2)
p
to the line segment [l1, l2]
.pointX
- the x coordinate of ppointY
- the y coordinate of plineX1
- the x coordinate of l1lineY1
- the y coordinate of l1lineX2
- the x coordinate of l2lineY2
- the y coordinate of l2public static final boolean leftTurn(YPoint p, YPoint q, YPoint r)
orientation(p,q,r) > 0
.public static final boolean linesIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
public static final int orientation(double px, double py, double qx, double qy, double rx, double ry)
orientation(YPoint, YPoint, YPoint)
with double values as arguments.public static final int orientation(YPoint p, YPoint q, YPoint r)
r
relative to the directed line from point p
to point q
.
The given tuple of points is said to have positive orientation if p
and q
are distinct and r
lies to the left of the oriented line passing through p
and q
and oriented from p
to q
.
The tuple is said to have negative orientation if p
and q
are distinct and r
lies to the right
of the line, and the tuple is said to have orientation zero if the three points are collinear.
public static final YPoint projection(double pointX, double pointY, double lineX1, double lineY1, double lineX2, double lineY2)
p
onto the line segment [l1, l2]
.
The resulting point is
p
onto the line through l1
and l2
, iff the projection lies on the
line segment [l1, l2]
[l1, l2]
that is closest to p
, otherwisepointX
- the x coordinate of ppointY
- the y coordinate of plineX1
- the x coordinate of l1lineY1
- the y coordinate of l1lineX2
- the x coordinate of l2lineY2
- the y coordinate of l2public static final boolean rightTurn(YPoint p, YPoint q, YPoint r)
orientation(p,q,r) < 0
.public static final int sideOfCircle(YPoint a, YPoint b, YPoint c, YPoint d)
d
lies left of the directed circle through points a
, b
, and c
, 0 if
a,b,c
and d
are cocircular, and -1 otherwise.public static final double toDegrees(double angrad)
public static final double toRadians(double angdeg)