Class CubicCurve2D

java.lang.Object
armyc2.c2sd.graphics2d.CubicCurve2D

public final class CubicCurve2D extends Object
The CubicCurve2D class defines a cubic parametric curve segment in (x,y) coordinate space.

This class is only the abstract superclass for all objects which store a 2D cubic curve segment. The actual storage representation of the coordinates is left to the subclass.

Since:
1.2
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    static double
    getFlatness(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2)
    Returns the flatness of the cubic curve specified by the indicated control points.
    static double
    getFlatness2(double[] coords, int offset)
    Returns the flatness of the cubic curve specified by the control points stored in the indicated array at the indicated index.
    static double
    getFlatnessSq(double[] coords, int offset)
    Returns the square of the flatness of the cubic curve specified by the control points stored in the indicated array at the indicated index.
    static double
    getFlatnessSq2(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2)
    Returns the square of the flatness of the cubic curve specified by the indicated control points.
    static int
    solveCubic(double[] eqn)
    Solves the cubic whose coefficients are in the eqn array and places the non-complex roots back into the same array, returning the number of roots.
    static int
    solveCubic2(double[] eqn, double[] res)
    Solve the cubic whose coefficients are in the eqn array and place the non-complex roots into the res array, returning the number of roots.
    static void
    subdivide(double[] src, int srcoff, double[] left, int leftoff, double[] right, int rightoff)
    Subdivides the cubic curve specified by the coordinates stored in the src array at indices srcoff through (srcoff + 7) and stores the resulting two subdivided curves into the two result arrays at the corresponding indices.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • getFlatnessSq2

      public static double getFlatnessSq2(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2)
      Returns the square of the flatness of the cubic curve specified by the indicated control points. The flatness is the maximum distance of a control point from the line connecting the end points.
      Parameters:
      x1 - the X coordinate that specifies the start point of a CubicCurve2D
      y1 - the Y coordinate that specifies the start point of a CubicCurve2D
      ctrlx1 - the X coordinate that specifies the first control point of a CubicCurve2D
      ctrly1 - the Y coordinate that specifies the first control point of a CubicCurve2D
      ctrlx2 - the X coordinate that specifies the second control point of a CubicCurve2D
      ctrly2 - the Y coordinate that specifies the second control point of a CubicCurve2D
      x2 - the X coordinate that specifies the end point of a CubicCurve2D
      y2 - the Y coordinate that specifies the end point of a CubicCurve2D
      Returns:
      the square of the flatness of the CubicCurve2D represented by the specified coordinates.
      Since:
      1.2
    • getFlatness

      public static double getFlatness(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2)
      Returns the flatness of the cubic curve specified by the indicated control points. The flatness is the maximum distance of a control point from the line connecting the end points.
      Parameters:
      x1 - the X coordinate that specifies the start point of a CubicCurve2D
      y1 - the Y coordinate that specifies the start point of a CubicCurve2D
      ctrlx1 - the X coordinate that specifies the first control point of a CubicCurve2D
      ctrly1 - the Y coordinate that specifies the first control point of a CubicCurve2D
      ctrlx2 - the X coordinate that specifies the second control point of a CubicCurve2D
      ctrly2 - the Y coordinate that specifies the second control point of a CubicCurve2D
      x2 - the X coordinate that specifies the end point of a CubicCurve2D
      y2 - the Y coordinate that specifies the end point of a CubicCurve2D
      Returns:
      the flatness of the CubicCurve2D represented by the specified coordinates.
      Since:
      1.2
    • getFlatnessSq

      public static double getFlatnessSq(double[] coords, int offset)
      Returns the square of the flatness of the cubic curve specified by the control points stored in the indicated array at the indicated index. The flatness is the maximum distance of a control point from the line connecting the end points.
      Parameters:
      coords - an array containing coordinates
      offset - the index of coords from which to begin getting the end points and control points of the curve
      Returns:
      the square of the flatness of the CubicCurve2D specified by the coordinates in coords at the specified offset.
      Since:
      1.2
    • getFlatness2

      public static double getFlatness2(double[] coords, int offset)
      Returns the flatness of the cubic curve specified by the control points stored in the indicated array at the indicated index. The flatness is the maximum distance of a control point from the line connecting the end points.
      Parameters:
      coords - an array containing coordinates
      offset - the index of coords from which to begin getting the end points and control points of the curve
      Returns:
      the flatness of the CubicCurve2D specified by the coordinates in coords at the specified offset.
      Since:
      1.2
    • subdivide

      public static void subdivide(double[] src, int srcoff, double[] left, int leftoff, double[] right, int rightoff)
      Subdivides the cubic curve specified by the coordinates stored in the src array at indices srcoff through (srcoff + 7) and stores the resulting two subdivided curves into the two result arrays at the corresponding indices. Either or both of the left and right arrays may be null or a reference to the same array as the src array. Note that the last point in the first subdivided curve is the same as the first point in the second subdivided curve. Thus, it is possible to pass the same array for left and right and to use offsets, such as rightoff equals (leftoff + 6), in order to avoid allocating extra storage for this common point.
      Parameters:
      src - the array holding the coordinates for the source curve
      srcoff - the offset into the array of the beginning of the the 6 source coordinates
      left - the array for storing the coordinates for the first half of the subdivided curve
      leftoff - the offset into the array of the beginning of the the 6 left coordinates
      right - the array for storing the coordinates for the second half of the subdivided curve
      rightoff - the offset into the array of the beginning of the the 6 right coordinates
      Since:
      1.2
    • solveCubic

      public static int solveCubic(double[] eqn)
      Solves the cubic whose coefficients are in the eqn array and places the non-complex roots back into the same array, returning the number of roots. The solved cubic is represented by the equation:
           eqn = {c, b, a, d}
           dx^3 + ax^2 + bx + c = 0
       
      A return value of -1 is used to distinguish a constant equation that might be always 0 or never 0 from an equation that has no zeroes.
      Parameters:
      eqn - an array containing coefficients for a cubic
      Returns:
      the number of roots, or -1 if the equation is a constant.
      Since:
      1.2
    • solveCubic2

      public static int solveCubic2(double[] eqn, double[] res)
      Solve the cubic whose coefficients are in the eqn array and place the non-complex roots into the res array, returning the number of roots. The cubic solved is represented by the equation: eqn = {c, b, a, d} dx^3 + ax^2 + bx + c = 0 A return value of -1 is used to distinguish a constant equation, which may be always 0 or never 0, from an equation which has no zeroes.
      Parameters:
      eqn - the specified array of coefficients to use to solve the cubic equation
      res - the array that contains the non-complex roots resulting from the solution of the cubic equation
      Returns:
      the number of roots, or -1 if the equation is a constant
      Since:
      1.3
    • clone

      public Object clone()
      Overrides:
      clone in class Object