Class FXGeom

java.lang.Object
org.jhotdraw8.geom.FXGeom

public class FXGeom extends Object
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 Type
    Method
    Description
    static double
    angle(javafx.geometry.Point2D a, javafx.geometry.Point2D b)
    Gets the angle of the specified line.
    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.
    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.
    static double
     
    static double
    distanceSq(@NonNull javafx.geometry.Point2D p, double x, double y)
     
    static double
    distanceSq(@NonNull javafx.geometry.Point2D p, @NonNull javafx.geometry.Point2D q)
     
    static @NonNull javafx.geometry.Point2D
    divide(@NonNull javafx.geometry.Point2D p, double factor)
     
    static @NonNull 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).
    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).
    static @NonNull javafx.geometry.Point3D
    homogenize(@NonNull javafx.geometry.Point3D p)
    Homogenizes the vector (x1,y1,z1) to (x1,y1,1).
    static @NonNull javafx.geometry.Point2D
    homogenize2D(@NonNull javafx.geometry.Point3D p)
    Homogenizes the vector (x1,y1,z1) to (x1,y1,1).
    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 null
    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.
    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.
    static double
    length(@NonNull javafx.geometry.Point2D p1, @NonNull javafx.geometry.Point2D p2)
    Gets the distance between to points
    static @NonNull javafx.geometry.Point2D
    lerp(double x0, double y0, double x1, double y1, double t)
     
    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.
    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.
    static @NonNull javafx.geometry.Point2D
    perp(double l1x, double l1y, double l2x, double l2y)
    Gets a unit vector which is perpendicular to the given line.
    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.
    static @NonNull javafx.geometry.Point2D
    perp(@NonNull javafx.geometry.Point2D vector)
    Gets the perpendicular vector to the given vector.
    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.
    static @NonNull javafx.geometry.Point2D
    polarToPoint(double angle, double fx, double fy)
    Converts a polar to a point
    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
    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
    static double
    squaredMagnitude(@NonNull javafx.geometry.Point2D p)
    Gets the squared magnitude of the given point.
    static @NonNull javafx.scene.transform.Transform
    toDeltaTransform(@NonNull javafx.scene.transform.Transform t)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 a
      end - point b
      t - 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

      public static @NonNull javafx.geometry.Point3D homogenize(@NonNull 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 @NonNull javafx.geometry.Point2D homogenize2D(@NonNull 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 point
      b - 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 rectangle
      angle - 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 point
      p1 - a point
      p2 - 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 shape
      p - 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 1
      p2 - 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 oval
      angle - the angle
      Returns:
      a point on the oval
    • perp

      public static @NonNull 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 line
      l1y - point 1 on the line
      l2x - point 2 on the line
      l2y - 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 rectangle
      p - the point
      Returns:
      the angle
    • polarToPoint

      public static @NonNull 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 coordinates
      fx - the x coordinate of the point in polar coordinates
      fy - 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 line
      l2 - point 2 on the line
      p - the point to be shifted
      distance - the shifting distance
      Returns:
      the shifted point
    • squaredMagnitude

      public static double squaredMagnitude(@NonNull 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 @NonNull javafx.geometry.Point2D perp(@NonNull 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 line
      l1y - point 1 on the line
      l2x - point 2 on the line
      l2y - point 2 on the line
      length - 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 line
      l1y - point 1 on the line
      l2x - point 2 on the line
      l2y - point 2 on the line
      px - the point to be shifted
      py - the point to be shifted
      distance - the shifting distance
      Returns:
      the shifted point
    • distanceSq

      public static double distanceSq(@NonNull javafx.geometry.Point2D p, @NonNull javafx.geometry.Point2D q)
    • distanceSq

      public static double distanceSq(@NonNull Point2D p, @NonNull Point2D q)
    • distanceSq

      public static double distanceSq(@NonNull 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 null

      from Doug Lea's PolygonFigure

      Parameters:
      xa - the x-coordinate of point a on line 1
      ya - the y-coordinate of point a on line 1
      xb - the x-coordinate of point b on line 1
      yb - the y-coordinate of point b on line 1
      xc - the x-coordinate of point c on line 2
      yc - the y-coordinate of point c on line 2
      xd - the x-coordinate of point d on line 2
      yd - 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 1
      ya - the y-coordinate of point a on line 1
      xb - the x-coordinate of point b on line 1
      yb - the y-coordinate of point b on line 1
      xc - the x-coordinate of point c on line 2
      yc - the y-coordinate of point c on line 2
      xd - the x-coordinate of point d on line 2
      yd - the y-coordinate of point d on line 2
      limit - 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 @NonNull javafx.geometry.Point2D divide(@NonNull javafx.geometry.Point2D p, double factor)
    • toDeltaTransform

      public static @NonNull javafx.scene.transform.Transform toDeltaTransform(@NonNull javafx.scene.transform.Transform t)
    • 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 1
      p2 - point 2
      Returns:
      the cross product
    • hcross

      public static @NonNull 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 - x1
      y1 - y1
      x2 - x2
      y2 - y2
      Returns:
      the cross product