Class Lines

java.lang.Object
org.jhotdraw8.geom.Lines

public class Lines extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    arcLength(double[] coords, int offset)
     
    static double
    arcLength(double x1, double y1, double x2, double y2)
    Gets the distance between to points
    static double
    arcLength(double x1, double y1, double x2, double y2, double t)
    Gets the arc length s at the given time t.
    static double
    distanceFromLine(double xa, double ya, double xb, double yb, double xc, double yc)
    compute distance of point from line segment, or Double.MAX_VALUE if perpendicular projection is outside segment; or If pts on line are same, return distance from point
    eval(double[] a, int offset, double t)
     
    eval(double x0, double y0, double x1, double y1, double t)
    Evaluates the given curve at the specified time.
    static double
    invArcLength(double[] p, int offset, double s)
    Computes time t at the given arc length s.
    static double
    invArcLength(double x1, double y1, double x2, double y2, double s)
    Computes time t at the given arc length s.
    static boolean
    isCollinear(double a, double b, double m, double n, double x, double y)
    Returns true if the three points are collinear.
    static boolean
    isCollinear(double a, double b, double m, double n, double x, double y, double tolerance)
     
    lerp(double[] a, int offset, double t)
     
    static double
    lerp(double a, double b, double t)
    Linear interpolation from a to b at t.
    lerp(double x0, double y0, double x1, double y1, double t)
     
    lerp(Point2D start, Point2D end, double t)
    Computes the linear interpolation/extrapolation between two points.
    static void
    split(double[] p, int o, double t, double @Nullable [] first, int offsetFirst, double @Nullable [] second, int offsetSecond)
    Splits the provided line into two parts.
    static void
    split(double x0, double y0, double x1, double y1, double t, @Nullable DoubleConsumer2 first, @Nullable DoubleConsumer2 second)
    Splits the provided line into two parts.
    static double
    squaredDistanceFromLine(double xa, double ya, double xb, double yb, double xc, double yc)
     
    static void
    subLine(double[] p, int o, double t0, double t1, double[] first, int offsetFirst)
    Extracts a sub-line.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Lines

      public Lines()
  • Method Details

    • eval

      public static PointAndDerivative eval(double x0, double y0, double x1, double y1, double t)
      Evaluates the given curve at the specified time.
      Parameters:
      x0 - point P0 of the curve
      y0 - point P0 of the curve
      x1 - point P1 of the curve
      y1 - point P1 of the curve
      t - the time
      Returns:
      the point at time t
    • isCollinear

      public static boolean isCollinear(double a, double b, double m, double n, double x, double y)
      Returns true if the three points are collinear.
      Parameters:
      a - x-coordinate of point 0
      b - y-coordinate of point 0
      m - x-coordinate of point 1
      n - y-coordinate of point 1
      x - x-coordinate of point 2
      y - y-coordinate of point 2
      Returns:
      true if collinear
    • isCollinear

      public static boolean isCollinear(double a, double b, double m, double n, double x, double y, double tolerance)
    • distanceFromLine

      public static double distanceFromLine(double xa, double ya, double xb, double yb, double xc, double yc)
      compute distance of point from line segment, or Double.MAX_VALUE if perpendicular projection is outside segment; or If pts on line are same, return distance from point
      Parameters:
      xa - the x-coordinate of point a on the line
      ya - the y-coordinate of point a on the line
      xb - the x-coordinate of point b on the line
      yb - the y-coordinate of point b on the line
      xc - the x-coordinate of the point c
      yc - the y-coordinate of the point c
      Returns:
      the distance from the line
    • squaredDistanceFromLine

      public static double squaredDistanceFromLine(double xa, double ya, double xb, double yb, double xc, double yc)
    • lerp

      public static double lerp(double a, double b, double t)
      Linear interpolation from a to b at t.
      Parameters:
      a - a
      b - b
      t - a value in the range [0, 1]
      Returns:
      the interpolated value
    • arcLength

      public static double arcLength(double x1, double y1, double x2, double y2)
      Gets the distance between to points
      Parameters:
      x1 - the x coordinate of point 1
      y1 - the y coordinate of point 1
      x2 - the x coordinate of point 2
      y2 - the y coordinate of point 2
      Returns:
      the distance between the two points
    • arcLength

      public static double arcLength(double[] coords, int offset)
    • arcLength

      public static double arcLength(double x1, double y1, double x2, double y2, double t)
      Gets the arc length s at the given time t.
      Parameters:
      x1 - the x coordinate of point 1
      y1 - the y coordinate of point 1
      x2 - the x coordinate of point 2
      y2 - the y coordinate of point 2
      t - the time
      Returns:
      arc length s at time t
    • invArcLength

      public static double invArcLength(double x1, double y1, double x2, double y2, double s)
      Computes time t at the given arc length s.
      Parameters:
      x1 - the x coordinate of point 1
      y1 - the y coordinate of point 1
      x2 - the x coordinate of point 2
      y2 - the y coordinate of point 2
      s - arc length
      Returns:
      t at s
    • invArcLength

      public static double invArcLength(double[] p, int offset, double s)
      Computes time t at the given arc length s.
      Parameters:
      p - points of the line
      offset - index of the first point in array a
      s - arc length
      Returns:
      t at s
    • split

      public static void split(double x0, double y0, double x1, double y1, double t, @Nullable DoubleConsumer2 first, @Nullable DoubleConsumer2 second)
      Splits the provided line into two parts.
      Parameters:
      x0 - point 1 of the line
      y0 - point 1 of the line
      x1 - point 2 of the line
      y1 - point 2 of the line
      t - where to split
      first - if not null, accepts the curve from x1,y1 to t1
      second - if not null, accepts the curve from t1 to x2,y2
    • split

      public static void split(double[] p, int o, double t, double @Nullable [] first, int offsetFirst, double @Nullable [] second, int offsetSecond)
      Splits the provided line into two parts.
    • subLine

      public static void subLine(double[] p, int o, double t0, double t1, double[] first, int offsetFirst)
      Extracts a sub-line.
    • lerp

      public static Point2D.Double lerp(double x0, double y0, double x1, double y1, double t)
    • lerp

      public static Point2D.Double lerp(double[] a, int offset, double t)
    • eval

      public static PointAndDerivative eval(double[] a, int offset, double t)
    • lerp

      public static Point2D.Double lerp(Point2D start, 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