Package armyc2.c2sd.graphics2d
Class CubicCurve2D
java.lang.Object
armyc2.c2sd.graphics2d.CubicCurve2D
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 -
Method Summary
Modifier and TypeMethodDescriptionclone()static doublegetFlatness(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 doublegetFlatness2(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 doublegetFlatnessSq(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 doublegetFlatnessSq2(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 intsolveCubic(double[] eqn) Solves the cubic whose coefficients are in theeqnarray and places the non-complex roots back into the same array, returning the number of roots.static intsolveCubic2(double[] eqn, double[] res) Solve the cubic whose coefficients are in theeqnarray and place the non-complex roots into theresarray, returning the number of roots.static voidsubdivide(double[] src, int srcoff, double[] left, int leftoff, double[] right, int rightoff) Subdivides the cubic curve specified by the coordinates stored in thesrcarray at indicessrcoffthrough (srcoff+ 7) and stores the resulting two subdivided curves into the two result arrays at the corresponding indices.
-
Constructor Details
-
CubicCurve2D
public CubicCurve2D()
-
-
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 aCubicCurve2Dy1- the Y coordinate that specifies the start point of aCubicCurve2Dctrlx1- the X coordinate that specifies the first control point of aCubicCurve2Dctrly1- the Y coordinate that specifies the first control point of aCubicCurve2Dctrlx2- the X coordinate that specifies the second control point of aCubicCurve2Dctrly2- the Y coordinate that specifies the second control point of aCubicCurve2Dx2- the X coordinate that specifies the end point of aCubicCurve2Dy2- the Y coordinate that specifies the end point of aCubicCurve2D- Returns:
- the square of the flatness of the
CubicCurve2Drepresented 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 aCubicCurve2Dy1- the Y coordinate that specifies the start point of aCubicCurve2Dctrlx1- the X coordinate that specifies the first control point of aCubicCurve2Dctrly1- the Y coordinate that specifies the first control point of aCubicCurve2Dctrlx2- the X coordinate that specifies the second control point of aCubicCurve2Dctrly2- the Y coordinate that specifies the second control point of aCubicCurve2Dx2- the X coordinate that specifies the end point of aCubicCurve2Dy2- the Y coordinate that specifies the end point of aCubicCurve2D- Returns:
- the flatness of the
CubicCurve2Drepresented by the specified coordinates. - Since:
- 1.2
-
getFlatnessSq
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 coordinatesoffset- the index ofcoordsfrom which to begin getting the end points and control points of the curve- Returns:
- the square of the flatness of the
CubicCurve2Dspecified by the coordinates incoordsat the specified offset. - Since:
- 1.2
-
getFlatness2
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 coordinatesoffset- the index ofcoordsfrom which to begin getting the end points and control points of the curve- Returns:
- the flatness of the
CubicCurve2Dspecified by the coordinates incoordsat 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 thesrcarray at indicessrcoffthrough (srcoff+ 7) and stores the resulting two subdivided curves into the two result arrays at the corresponding indices. Either or both of theleftandrightarrays may benullor a reference to the same array as thesrcarray. 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 forleftandrightand to use offsets, such asrightoffequals (leftoff+ 6), in order to avoid allocating extra storage for this common point.- Parameters:
src- the array holding the coordinates for the source curvesrcoff- the offset into the array of the beginning of the the 6 source coordinatesleft- the array for storing the coordinates for the first half of the subdivided curveleftoff- the offset into the array of the beginning of the the 6 left coordinatesright- the array for storing the coordinates for the second half of the subdivided curverightoff- the offset into the array of the beginning of the the 6 right coordinates- Since:
- 1.2
-
solveCubic
Solves the cubic whose coefficients are in theeqnarray 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 = 0A 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
Solve the cubic whose coefficients are in theeqnarray and place the non-complex roots into theresarray, 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 equationres- 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
-