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 javafx.geometry.Point2DangleToPoint(javafx.geometry.Rectangle2D r, double angle) Gets the point on a rectangle that corresponds to the given angle.static 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(Point2D p, Point2D q) static doubledistanceSq(javafx.geometry.Point2D p, double x, double y) static doubledistanceSq(javafx.geometry.Point2D p, javafx.geometry.Point2D q) static javafx.geometry.Point2Ddivide(javafx.geometry.Point2D p, double factor) static 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 javafx.geometry.Point3Dhcross(javafx.geometry.Point2D p1, javafx.geometry.Point2D p2) Computes the cross product of the homogenous vectors (x1,y1,1) x (x2,y2,1).static javafx.geometry.Point3Dhomogenize(javafx.geometry.Point3D p) Homogenizes the vector (x1,y1,z1) to (x1,y1,1).static javafx.geometry.Point2Dhomogenize2D(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(javafx.geometry.Point2D p0, javafx.geometry.Point2D p1, javafx.geometry.Point2D p2) Returns true if the three points are collinear.static doublelength(javafx.geometry.Point2D p1, javafx.geometry.Point2D p2) Gets the distance between to pointsstatic javafx.geometry.Point2Dlerp(double x0, double y0, double x1, double y1, double t) static javafx.geometry.Point2Dlerp(javafx.geometry.Point2D start, javafx.geometry.Point2D end, double t) Computes the linear interpolation/extrapolation between two points.static javafx.geometry.Point2DovalAngleToPoint(javafx.geometry.Rectangle2D r, double angle) Gets the point on an oval that corresponds to the given angle.static 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 javafx.geometry.Point2Dperp(javafx.geometry.Point2D vector) Gets the perpendicular vector to the given vector.static doublepointToAngle(javafx.geometry.Rectangle2D r, javafx.geometry.Point2D p) Gets the angle of a point relative to the center of a rectangle.static javafx.geometry.Point2DpolarToPoint(double angle, double fx, double fy) Converts a polar to a pointstatic 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 javafx.geometry.Point2DshiftPerp(javafx.geometry.Point2D l1, javafx.geometry.Point2D l2, javafx.geometry.Point2D p, double distance) Shifts the point perpendicular to the line by the given distancestatic doublesquaredMagnitude(javafx.geometry.Point2D p) Gets the squared magnitude of the given point.static javafx.scene.transform.TransformtoDeltaTransform(javafx.scene.transform.Transform t)
-
Method Details
-
lerp
public static javafx.geometry.Point2D lerp(javafx.geometry.Point2D start, 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 javafx.geometry.Point2D lerp(double x0, double y0, double x1, double y1, double t) -
homogenize
public static javafx.geometry.Point3D homogenize(javafx.geometry.Point3D p) 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
public static javafx.geometry.Point2D homogenize2D(javafx.geometry.Point3D p) 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 javafx.geometry.Point2D angleToPoint(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(javafx.geometry.Point2D p0, javafx.geometry.Point2D p1, 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
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(javafx.geometry.Point2D p1, 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 javafx.geometry.Point2D ovalAngleToPoint(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
public static javafx.geometry.Point2D perp(double l1x, double l1y, double l2x, double l2y) 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(javafx.geometry.Rectangle2D r, 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
public static javafx.geometry.Point2D polarToPoint(double angle, double fx, double fy) 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 javafx.geometry.Point2D shiftPerp(javafx.geometry.Point2D l1, javafx.geometry.Point2D l2, 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
public static double squaredMagnitude(javafx.geometry.Point2D p) Gets the squared magnitude of the given point.- Parameters:
p- a point- Returns:
- the squared distance of the point to (0,0)
-
perp
public static javafx.geometry.Point2D perp(javafx.geometry.Point2D vector) 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 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
public static double distanceSq(javafx.geometry.Point2D p, javafx.geometry.Point2D q) -
distanceSq
-
distanceSq
public static double distanceSq(javafx.geometry.Point2D p, double x, double y) -
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
public static javafx.geometry.Point2D divide(javafx.geometry.Point2D p, double factor) -
toDeltaTransform
public static javafx.scene.transform.Transform toDeltaTransform(javafx.scene.transform.Transform t) -
hcross
public static javafx.geometry.Point3D hcross(javafx.geometry.Point2D p1, 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
public static javafx.geometry.Point3D hcross(double x1, double y1, double x2, double y2) 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
-