java.awt.geom

Class CubicCurve2D

Implemented Interfaces:
Cloneable, Shape
Known Direct Subclasses:
CubicCurve2D.Double, CubicCurve2D.Float

public abstract class CubicCurve2D
extends Object
implements Shape, Cloneable

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.

Nested Class Summary

static class
CubicCurve2D.Double
A cubic parametric curve segment specified with double coordinates.
static class
CubicCurve2D.Float
A cubic parametric curve segment specified with float coordinates.

Constructor Summary

CubicCurve2D()
This is an abstract class that cannot be instantiated directly.

Method Summary

Object
clone()
Creates a new object of the same class as this object.
boolean
contains(double x, double y)
Tests if a specified coordinate is inside the boundary of the shape.
boolean
contains(double x, double y, double w, double h)
Tests if the interior of the shape entirely contains the specified set of rectangular coordinates.
boolean
contains(Point2D p)
Tests if a specified Point2D is inside the boundary of the shape.
boolean
contains(Rectangle2D r)
Tests if the interior of the shape entirely contains the specified Rectangle2D.
Rectangle
getBounds()
Returns the bounding box of the shape.
abstract Point2D
getCtrlP1()
Returns the first control point.
abstract Point2D
getCtrlP2()
Returns the second control point.
abstract double
getCtrlX1()
Returns the X coordinate of the first control point in double precision.
abstract double
getCtrlX2()
Returns the X coordinate of the second control point in double precision.
abstract double
getCtrlY1()
Returns the Y coordinate of the first control point in double precision.
abstract double
getCtrlY2()
Returns the Y coordinate of the second control point in double precision.
double
getFlatness()
Returns the flatness of this curve.
static double
getFlatness(coords[] , int offset)
Returns the flatness of the cubic curve specified by the controlpoints stored in the indicated array at the indicated index.
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 controlpoints.
double
getFlatnessSq()
Returns the square of the flatness of this curve.
static double
getFlatnessSq(coords[] , int offset)
Returns the square of the flatness of the cubic curve specified by the controlpoints stored in the indicated array at the indicated index.
static double
getFlatnessSq(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 controlpoints.
abstract Point2D
getP1()
Returns the start point.
abstract Point2D
getP2()
Returns the end point.
PathIterator
getPathIterator(AffineTransform at)
Returns an iteration object that defines the boundary of the shape.
PathIterator
getPathIterator(AffineTransform at, double flatness)
Return an iteration object that defines the boundary of the flattened shape.
abstract double
getX1()
Returns the X coordinate of the start point in double precision.
abstract double
getX2()
Returns the X coordinate of the end point in double precision.
abstract double
getY1()
Returns the Y coordinate of the start point in double precision.
abstract double
getY2()
Returns the Y coordinate of the end point in double precision.
boolean
intersects(double x, double y, double w, double h)
Tests if the shape intersects the interior of a specified set of rectangular coordinates.
boolean
intersects(Rectangle2D r)
Tests if the shape intersects the interior of a specified Rectangle2D.
abstract void
setCurve(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2)
Sets the location of the endpoints and controlpoints of this curve to the specified double coordinates.
void
setCurve(double[] coords, int offset)
Sets the location of the endpoints and controlpoints of this curve to the double coordinates at the specified offset in the specified array.
void
setCurve(CubicCurve2D c)
Sets the location of the endpoints and controlpoints of this curve to the same as those in the specified CubicCurve2D.
void
setCurve(Point2D p1, Point2D cp1, Point2D cp2, Point2D p2)
Sets the location of the endpoints and controlpoints of this curve to the specified Point2D coordinates.
void
setCurve(Point2D[] pts, int offset)
Sets the location of the endpoints and controlpoints of this curve to the coordinates of the Point2D objects at the specified offset in the specified array.
static int
solveCubic(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
solveCubic(eqn[] , 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.
void
subdivide(CubicCurve2D left, CubicCurve2D right)
Subdivides this cubic curve and stores the resulting two subdivided curves into the left and right curve parameters.
static void
subdivide(CubicCurve2D src, CubicCurve2D left, CubicCurve2D right)
Subdivides the cubic curve specified by the src parameter and stores the resulting two subdivided curves into the left and right curve parameters.
static void
subdivide(src[] , int srcoff, left[] , int leftoff, 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

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

CubicCurve2D

protected CubicCurve2D()
This is an abstract class that cannot be instantiated directly. Type-specific implementation subclasses are available for instantiation and provide a number of formats for storing the information necessary to satisfy the various accessor methods below.

Method Details

clone

public Object clone()
Creates a new object of the same class as this object.
Overrides:
clone in interface Object
Returns:
a clone of this instance.
Since:
1.2
See Also:
Cloneable

contains

public boolean contains(double x,
                        double y)
Tests if a specified coordinate is inside the boundary of the shape.
Specified by:
contains in interface Shape
Parameters:
Returns:
true if the coordinate is inside the boundary of the shape; false otherwise.

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Tests if the interior of the shape entirely contains the specified set of rectangular coordinates.
Specified by:
contains in interface Shape
Parameters:
w - the width of the specified rectangular shape
h - the height of the specified rectangular shape
Returns:
true if the shape entirely contains the specified set of rectangular coordinates; false otherwise.

contains

public boolean contains(Point2D p)
Tests if a specified Point2D is inside the boundary of the shape.
Specified by:
contains in interface Shape
Parameters:
p - the specified Point2D to be tested
Returns:
true if the p is inside the boundary of the shape; false otherwise.

contains

public boolean contains(Rectangle2D r)
Tests if the interior of the shape entirely contains the specified Rectangle2D.
Specified by:
contains in interface Shape
Parameters:
r - the specified Rectangle2D to be tested
Returns:
true if the shape entirely contains the specified Rectangle2D; false otherwise.

getBounds

public Rectangle getBounds()
Returns the bounding box of the shape.
Specified by:
getBounds in interface Shape
Returns:
a Rectangle that is the bounding box of the shape.

getCtrlP1

public abstract Point2D getCtrlP1()
Returns the first control point.
Returns:
a Point2D that is the first control point of the CubicCurve2D.

getCtrlP2

public abstract Point2D getCtrlP2()
Returns the second control point.
Returns:
a Point2D that is the second control point of the CubicCurve2D.

getCtrlX1

public abstract double getCtrlX1()
Returns the X coordinate of the first control point in double precision.
Returns:
the X coordinate of the first control point of the CubicCurve2D.

getCtrlX2

public abstract double getCtrlX2()
Returns the X coordinate of the second control point in double precision.
Returns:
the X coordinate of the second control point of the CubicCurve2D.

getCtrlY1

public abstract double getCtrlY1()
Returns the Y coordinate of the first control point in double precision.
Returns:
the Y coordinate of the first control point of the CubicCurve2D.

getCtrlY2

public abstract double getCtrlY2()
Returns the Y coordinate of the second control point in double precision.
Returns:
the Y coordinate of the second control point of the CubicCurve2D.

getFlatness

public double getFlatness()
Returns the flatness of this curve. The flatness is the maximum distance of a controlpoint from the line connecting the endpoints.
Returns:
the flatness of this curve.

getFlatness

public static double getFlatness(coords[] ,
                                 int offset)
Returns the flatness of the cubic curve specified by the controlpoints stored in the indicated array at the indicated index. The flatness is the maximum distance of a controlpoint from the line connecting the endpoints.
Parameters:
offset - the index of coords at which to begin setting the endpoints and controlpoints of this curve to the coordinates contained in coords
Returns:
the flatness of the CubicCurve2D specified by the coordinates in coords at the specified offset.

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 controlpoints. The flatness is the maximum distance of a controlpoint from the line connecting the endpoints.
Parameters:
Returns:
the flatness of the CubicCurve2D represented by the specified coordinates.

getFlatnessSq

public double getFlatnessSq()
Returns the square of the flatness of this curve. The flatness is the maximum distance of a controlpoint from the line connecting the endpoints.
Returns:
the square of the flatness of this curve.

getFlatnessSq

public static double getFlatnessSq(coords[] ,
                                   int offset)
Returns the square of the flatness of the cubic curve specified by the controlpoints stored in the indicated array at the indicated index. The flatness is the maximum distance of a controlpoint from the line connecting the endpoints.
Parameters:
offset - the index of coords at which to begin setting the endpoints and controlpoints of this curve to the coordinates contained in coords
Returns:
the square of the flatness of the CubicCurve2D specified by the coordinates in coords at the specified offset.

getFlatnessSq

public static double getFlatnessSq(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 controlpoints. The flatness is the maximum distance of a controlpoint from the line connecting the endpoints.
Parameters:
Returns:
the square of the flatness of the CubicCurve2D represented by the specified coordinates.

getP1

public abstract Point2D getP1()
Returns the start point.
Returns:
a Point2D that is the start point of the CubicCurve2D.

getP2

public abstract Point2D getP2()
Returns the end point.
Returns:
a Point2D that is the end point of the CubicCurve2D.

getPathIterator

public PathIterator getPathIterator(AffineTransform at)
Returns an iteration object that defines the boundary of the shape. The iterator for this class is not multi-threaded safe, which means that this CubicCurve2D class does not guarantee that modifications to the geometry of this CubicCurve2D object do not affect any iterations of that geometry that are already in process.
Specified by:
getPathIterator in interface Shape
Parameters:
at - an optional AffineTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired
Returns:
the PathIterator object that returns the geometry of the outline of this CubicCurve2D, one segment at a time.

getPathIterator

public PathIterator getPathIterator(AffineTransform at,
                                    double flatness)
Return an iteration object that defines the boundary of the flattened shape. The iterator for this class is not multi-threaded safe, which means that this CubicCurve2D class does not guarantee that modifications to the geometry of this CubicCurve2D object do not affect any iterations of that geometry that are already in process.
Specified by:
getPathIterator in interface Shape
Parameters:
at - an optional AffineTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired
flatness - the maximum amount that the control points for a given curve can vary from colinear before a subdivided curve is replaced by a straight line connecting the endpoints
Returns:
the PathIterator object that returns the geometry of the outline of this CubicCurve2D, one segment at a time.
Usages and Demos :

View More Examples of getPathIterator(AffineTransform at,double flatness)
   1: import java.awt.event.ActionListener;
   2: import java.awt.geom.CubicCurve2D;
   3: import java.awt.geom.Point2D;
   4:         ...
   5:     public void reset(int w, int h) {
   6:         CubicCurve2D cc = new CubicCurve2D.Float(
   7:                         w*.2f, h*.5f, w*.4f,0, w*.6f,h,w*.8f,h*.5f);
   8:         ...
   9:         PathIterator pi = cc.getPathIterator(null, 0.1);
  10:         Point2D tmp[] = new Point2D[200];

View Full Code Here
   1: import java.awt.*;
   2: import java.awt.geom.CubicCurve2D;
   3: import java.awt.geom.Point2D;
   4:         ...
   5:         direction = FORWARD;
   6:         CubicCurve2D cc = new CubicCurve2D.Float(
   7:                         w*.2f, h*.5f, w*.4f,0, w*.6f,h,w*.8f,h*.5f);
   8:         ...
   9:         PathIterator pi = cc.getPathIterator(null, 0.1);
  10:         Point2D tmp[] = new Point2D[200];

View Full Code Here

getX1

public abstract double getX1()
Returns the X coordinate of the start point in double precision.
Returns:
the X coordinate of the start point of the CubicCurve2D.

getX2

public abstract double getX2()
Returns the X coordinate of the end point in double precision.
Returns:
the X coordinate of the end point of the CubicCurve2D.

getY1

public abstract double getY1()
Returns the Y coordinate of the start point in double precision.
Returns:
the Y coordinate of the start point of the CubicCurve2D.

getY2

public abstract double getY2()
Returns the Y coordinate of the end point in double precision.
Returns:
the Y coordinate of the end point of the CubicCurve2D.

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Tests if the shape intersects the interior of a specified set of rectangular coordinates.
Specified by:
intersects in interface Shape
Parameters:
w - the width of the specified rectangular area
h - the height of the specified rectangular area
Returns:
true if the shape intersects the interior of the specified rectangular area; false otherwise.

intersects

public boolean intersects(Rectangle2D r)
Tests if the shape intersects the interior of a specified Rectangle2D.
Specified by:
intersects in interface Shape
Parameters:
r - the specified Rectangle2D to be tested
Returns:
true if the shape intersects the interior of the specified Rectangle2D; false otherwise.

setCurve

public abstract void setCurve(double x1,
                              double y1,
                              double ctrlx1,
                              double ctrly1,
                              double ctrlx2,
                              double ctrly2,
                              double x2,
                              double y2)
Sets the location of the endpoints and controlpoints of this curve to the specified double coordinates.
Parameters:

setCurve

public void setCurve(double[] coords,
                     int offset)
Sets the location of the endpoints and controlpoints of this curve to the double coordinates at the specified offset in the specified array.
Parameters:
coords - a double array containing coordinates
offset - the index of coords at which to begin setting the endpoints and controlpoints of this curve to the coordinates contained in coords

setCurve

public void setCurve(CubicCurve2D c)
Sets the location of the endpoints and controlpoints of this curve to the same as those in the specified CubicCurve2D.
Parameters:
c - the specified CubicCurve2D

setCurve

public void setCurve(Point2D p1,
                     Point2D cp1,
                     Point2D cp2,
                     Point2D p2)
Sets the location of the endpoints and controlpoints of this curve to the specified Point2D coordinates.
Parameters:
p1 - the first specified Point2D used to set the start point of this curve
cp1 - the second specified Point2D used to set the first control point of this curve
cp2 - the third specified Point2D used to set the second control point of this curve
p2 - the fourth specified Point2D used to set the end point of this curve

setCurve

public void setCurve(Point2D[] pts,
                     int offset)
Sets the location of the endpoints and controlpoints of this curve to the coordinates of the Point2D objects at the specified offset in the specified array.
Parameters:
pts - an array of Point2D objects
offset - the index of pts at which to begin setting the endpoints and controlpoints of this curve to the points contained in pts

solveCubic

public static int solveCubic(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:
Returns:
the number of roots, or -1 if the equation is a constant.

solveCubic

public static int solveCubic(eqn[] ,
                             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:
Returns:
the number of roots, or -1 if the equation is a constant
Usages and Demos :

View More Examples of solveCubic(eqn[] ,res[] )
   1: 
   2: import java.awt.geom.CubicCurve2D;
   3: import java.awt.geom.Point2D;
   4:         ...
   5:                           3*p2.y-p1.y+p4.y-3*p3.y };
   6:         return CubicCurve2D.solveCubic(eqn, roots);
   7:     }
   8: 
   9:     public Point2D.Double evalDt(double t) {

View Full Code Here

subdivide

public void subdivide(CubicCurve2D left,
                      CubicCurve2D right)
Subdivides this cubic curve and stores the resulting two subdivided curves into the left and right curve parameters. Either or both of the left and right objects may be the same as this object or null.
Parameters:
left - the cubic curve object for storing for the left or first half of the subdivided curve
right - the cubic curve object for storing for the right or second half of the subdivided curve

subdivide

public static void subdivide(CubicCurve2D src,
                             CubicCurve2D left,
                             CubicCurve2D right)
Subdivides the cubic curve specified by the src parameter and stores the resulting two subdivided curves into the left and right curve parameters. Either or both of the left and right objects may be the same as the src object or null.
Parameters:
src - the cubic curve to be subdivided
left - the cubic curve object for storing the left or first half of the subdivided curve
right - the cubic curve object for storing the right or second half of the subdivided curve

subdivide

public static void subdivide(src[] ,
                             int srcoff,
                             left[] ,
                             int leftoff,
                             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:
srcoff - the offset into the array of the beginning of the the 6 source coordinates
leftoff - the offset into the array of the beginning of the the 6 left coordinates
rightoff - the offset into the array of the beginning of the the 6 right coordinates