java.lang.Object
org.jhotdraw8.geom.FXGeom
This class provides utility functions for two dimensional geometry
based on the javafx.graphics module (FX), as well as translation
functions from/to geometric objects of the java.desktop module (AWT).
.
-
Method Summary
Modifier and TypeMethodDescriptionstatic doubleangle(javafx.geometry.Point2D a, javafx.geometry.Point2D b) Gets the angle of the specified line.static @NonNull javafx.geometry.Point2DangleToPoint(@NonNull javafx.geometry.Rectangle2D r, double angle) Gets the point on a rectangle that corresponds to the given angle.static @NonNull javafx.geometry.Point2DReturns a point on the edge of the shape which crosses the line from the center of the shape to the specified point.static doubledistanceSq(@NonNull Point2D p, @NonNull Point2D q) static doubledistanceSq(@NonNull javafx.geometry.Point2D p, double x, double y) static doubledistanceSq(@NonNull javafx.geometry.Point2D p, @NonNull javafx.geometry.Point2D q) static @NonNull javafx.geometry.Point2Dstatic @NonNull javafx.geometry.Point3Dhcross(double x1, double y1, double x2, double y2) Computes the cross product of the homogenous vectors (x1,y1,1) x (x2,y2,1).static @NonNull javafx.geometry.Point3DComputes the cross product of the homogenous vectors (x1,y1,1) x (x2,y2,1).static @NonNull javafx.geometry.Point3Dhomogenize(@NonNull javafx.geometry.Point3D p) Homogenizes the vector (x1,y1,z1) to (x1,y1,1).static @NonNull javafx.geometry.Point2Dhomogenize2D(@NonNull javafx.geometry.Point3D p) Homogenizes the vector (x1,y1,z1) to (x1,y1,1).static @Nullable javafx.geometry.Point2Dintersect(double xa, double ya, double xb, double yb, double xc, double yc, double xd, double yd) Standard line intersection algorithm Return the point of intersection if it exists, else nullstatic @Nullable javafx.geometry.Point2Dintersect(double xa, double ya, double xb, double yb, double xc, double yc, double xd, double yd, double limit) Line intersection algorithm Return the point of intersection if it exists, else null.static booleanisCollinear(@NonNull javafx.geometry.Point2D p0, @NonNull javafx.geometry.Point2D p1, @NonNull javafx.geometry.Point2D p2) Returns true if the three points are collinear.static doubleGets the distance between to pointsstatic @NonNull javafx.geometry.Point2Dlerp(double x0, double y0, double x1, double y1, double t) static @NonNull javafx.geometry.Point2DComputes the linear interpolation/extrapolation between two points.static @NonNull javafx.geometry.Point2DovalAngleToPoint(@NonNull javafx.geometry.Rectangle2D r, double angle) Gets the point on an oval that corresponds to the given angle.static @NonNull javafx.geometry.Point2Dperp(double l1x, double l1y, double l2x, double l2y) Gets a unit vector which is perpendicular to the given line.static javafx.geometry.Point2Dperp(double l1x, double l1y, double l2x, double l2y, double length) Gets a vector which is perpendicular to the given line.static @NonNull javafx.geometry.Point2DGets the perpendicular vector to the given vector.static doublepointToAngle(@NonNull javafx.geometry.Rectangle2D r, @NonNull javafx.geometry.Point2D p) Gets the angle of a point relative to the center of a rectangle.static @NonNull javafx.geometry.Point2DpolarToPoint(double angle, double fx, double fy) Converts a polar to a pointstatic @NonNull javafx.geometry.Point2DshiftPerp(double l1x, double l1y, double l2x, double l2y, double px, double py, double distance) Shifts the point perpendicular to the line by the given distancestatic @NonNull javafx.geometry.Point2DshiftPerp(@NonNull javafx.geometry.Point2D l1, @NonNull javafx.geometry.Point2D l2, @NonNull javafx.geometry.Point2D p, double distance) Shifts the point perpendicular to the line by the given distancestatic doublesquaredMagnitude(@NonNull javafx.geometry.Point2D p) Gets the squared magnitude of the given point.static @NonNull javafx.scene.transform.TransformtoDeltaTransform(@NonNull javafx.scene.transform.Transform t)
-
Method Details
-
lerp
public static @NonNull javafx.geometry.Point2D lerp(@NonNull javafx.geometry.Point2D start, @NonNull javafx.geometry.Point2D end, double t) Computes the linear interpolation/extrapolation between two points.- Parameters:
start- point aend- point bt- a value between [0, 1] defines the interpolation between a and b. Values outside this range yield an extrapolation.- Returns:
- the interpolated or extrapolated value
-
lerp
public static @NonNull javafx.geometry.Point2D lerp(double x0, double y0, double x1, double y1, double t) -
homogenize
Homogenizes the vector (x1,y1,z1) to (x1,y1,1).( y1 / z1, z1 / z1, 1 )With z1=1 and z2=1;- Parameters:
p- the vector- Returns:
- the normalized vector
-
homogenize2D
Homogenizes the vector (x1,y1,z1) to (x1,y1,1).( y1 / z1, z1 / z1, 1 )With z1=1 and z2=1;- Parameters:
p- the vector- Returns:
- the normalized vector
-
angle
public static double angle(javafx.geometry.Point2D a, javafx.geometry.Point2D b) Gets the angle of the specified line.- Parameters:
a- the start pointb- the end point- Returns:
- the angle in radians
-
angleToPoint
public static @NonNull javafx.geometry.Point2D angleToPoint(@NonNull javafx.geometry.Rectangle2D r, double angle) Gets the point on a rectangle that corresponds to the given angle.- Parameters:
r- the rectangleangle- the angle of the ray starting at the center of the rectangle- Returns:
- a point on the rectangle
-
isCollinear
public static boolean isCollinear(@NonNull javafx.geometry.Point2D p0, @NonNull javafx.geometry.Point2D p1, @NonNull javafx.geometry.Point2D p2) Returns true if the three points are collinear.- Parameters:
p0- a pointp1- a pointp2- a point- Returns:
- true if the area is 0
-
chop
public static @NonNull javafx.geometry.Point2D chop(@NonNull Shape shape, @NonNull javafx.geometry.Point2D p) Returns a point on the edge of the shape which crosses the line from the center of the shape to the specified point. If no edge crosses of the shape crosses the line, the nearest control point of the shape is returned.- Parameters:
shape- the shapep- the point- Returns:
- a point on the shape
-
length
public static double length(@NonNull javafx.geometry.Point2D p1, @NonNull javafx.geometry.Point2D p2) Gets the distance between to points- Parameters:
p1- point 1p2- point 2- Returns:
- the distance between the two points
-
ovalAngleToPoint
public static @NonNull javafx.geometry.Point2D ovalAngleToPoint(@NonNull javafx.geometry.Rectangle2D r, double angle) Gets the point on an oval that corresponds to the given angle.- Parameters:
r- the bounds of the ovalangle- the angle- Returns:
- a point on the oval
-
perp
Gets a unit vector which is perpendicular to the given line.- Parameters:
l1x- point 1 on the linel1y- point 1 on the linel2x- point 2 on the linel2y- point 2 on the line- Returns:
- the perpendicular vector of length
1
-
pointToAngle
public static double pointToAngle(@NonNull javafx.geometry.Rectangle2D r, @NonNull javafx.geometry.Point2D p) Gets the angle of a point relative to the center of a rectangle.- Parameters:
r- the rectanglep- the point- Returns:
- the angle
-
polarToPoint
Converts a polar to a point- Parameters:
angle- the angle of the point in polar coordinatesfx- the x coordinate of the point in polar coordinatesfy- the y coordinate of the point in polar coordinates- Returns:
- the point in Cartesian coordinates
-
shiftPerp
public static @NonNull javafx.geometry.Point2D shiftPerp(@NonNull javafx.geometry.Point2D l1, @NonNull javafx.geometry.Point2D l2, @NonNull javafx.geometry.Point2D p, double distance) Shifts the point perpendicular to the line by the given distance- Parameters:
l1- point 1 on the linel2- point 2 on the linep- the point to be shifteddistance- the shifting distance- Returns:
- the shifted point
-
squaredMagnitude
Gets the squared magnitude of the given point.- Parameters:
p- a point- Returns:
- the squared distance of the point to (0,0)
-
perp
Gets the perpendicular vector to the given vector.- Parameters:
vector- a vector- Returns:
- the perpendicular vector
-
perp
public static javafx.geometry.Point2D perp(double l1x, double l1y, double l2x, double l2y, double length) Gets a vector which is perpendicular to the given line.- Parameters:
l1x- point 1 on the linel1y- point 1 on the linel2x- point 2 on the linel2y- point 2 on the linelength- the desired length of the vector- Returns:
- the perpendicular vector of length
vectorLength
-
shiftPerp
public static @NonNull javafx.geometry.Point2D shiftPerp(double l1x, double l1y, double l2x, double l2y, double px, double py, double distance) Shifts the point perpendicular to the line by the given distance- Parameters:
l1x- point 1 on the linel1y- point 1 on the linel2x- point 2 on the linel2y- point 2 on the linepx- the point to be shiftedpy- the point to be shifteddistance- the shifting distance- Returns:
- the shifted point
-
distanceSq
-
distanceSq
-
distanceSq
-
intersect
public static @Nullable javafx.geometry.Point2D intersect(double xa, double ya, double xb, double yb, double xc, double yc, double xd, double yd) Standard line intersection algorithm Return the point of intersection if it exists, else nullfrom Doug Lea's PolygonFigure
- Parameters:
xa- the x-coordinate of point a on line 1ya- the y-coordinate of point a on line 1xb- the x-coordinate of point b on line 1yb- the y-coordinate of point b on line 1xc- the x-coordinate of point c on line 2yc- the y-coordinate of point c on line 2xd- the x-coordinate of point d on line 2yd- the y-coordinate of point d on line 2- Returns:
- the intersection point or null
-
intersect
public static @Nullable javafx.geometry.Point2D intersect(double xa, double ya, double xb, double yb, double xc, double yc, double xd, double yd, double limit) Line intersection algorithm Return the point of intersection if it exists, else null.- Parameters:
xa- the x-coordinate of point a on line 1ya- the y-coordinate of point a on line 1xb- the x-coordinate of point b on line 1yb- the y-coordinate of point b on line 1xc- the x-coordinate of point c on line 2yc- the y-coordinate of point c on line 2xd- the x-coordinate of point d on line 2yd- the y-coordinate of point d on line 2limit- the lines are extend by up to limit units in order to meet at the intersection point- Returns:
- the intersection point or null
-
divide
-
toDeltaTransform
-
hcross
public static @NonNull javafx.geometry.Point3D hcross(@NonNull javafx.geometry.Point2D p1, @NonNull javafx.geometry.Point2D p2) Computes the cross product of the homogenous vectors (x1,y1,1) x (x2,y2,1).( y1 * z2 - z1 * y2, z1 * x2 - x1 * z2, x1 * y2 - y1 * x2 )With z1=1 and z2=1;- Parameters:
p1- point 1p2- point 2- Returns:
- the cross product
-
hcross
Computes the cross product of the homogenous vectors (x1,y1,1) x (x2,y2,1).( y1 * z2 - z1 * y2, z1 * x2 - x1 * z2, x1 * y2 - y1 * x2 )With z1=1 and z2=1;- Parameters:
x1- x1y1- y1x2- x2y2- y2- Returns:
- the cross product
-