java.awt.geom

Class QuadCurve2D

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

public abstract class QuadCurve2D
extends Object
implements Shape, Cloneable

The QuadCurve2D class defines a quadratic parametric curve segment in (x, y) coordinate space.

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

Nested Class Summary

static class
QuadCurve2D.Double
A quadratic parametric curve segment specified with double coordinates.
static class
QuadCurve2D.Float
A quadratic parametric curve segment specified with float coordinates.

Constructor Summary

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

Method Summary

Object
clone()
Creates a new object of the same class and with the same contents as this object.
boolean
contains(double x, double y)
Tests if a specified coordinate is inside the boundary of the shape of this QuadCurve2D.
boolean
contains(double x, double y, double w, double h)
Tests if the interior of the shape of this QuadCurve2D entirely contains the specified set of rectangular coordinates.
boolean
contains(Point2D p)
Tests if a specified Point2D is inside the boundary of the shape of this QuadCurve2D.
boolean
contains(Rectangle2D r)
Tests if the interior of the shape of this QuadCurve2D entirely contains the specified Rectangle2D.
Rectangle
getBounds()
Returns the bounding box of this QuadCurve2D.
abstract Point2D
getCtrlPt()
Returns the control point.
abstract double
getCtrlX()
Returns the x coordinate of the control point in double precision.
abstract double
getCtrlY()
Returns the y coordinate of the control point in double precision.
double
getFlatness()
Returns the flatness, or maximum distance of a controlpoint from the line connecting the endpoints, of this QuadCurve2D.
static double
getFlatness(coords[] , int offset)
Returns the flatness, or maximum distance of a controlpoint from the line connecting the endpoints, of the quadratic curve specified by the controlpoints stored in the indicated array at the indicated index.
static double
getFlatness(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)
Returns the flatness, or maximum distance of a controlpoint from the line connecting the endpoints, of the quadratic curve specified by the indicated controlpoints.
double
getFlatnessSq()
Returns the square of the flatness, or maximum distance of a controlpoint from the line connecting the endpoints, of this QuadCurve2D.
static double
getFlatnessSq(coords[] , int offset)
Returns the square of the flatness, or maximum distance of a controlpoint from the line connecting the endpoints, of the quadratic curve specified by the controlpoints stored in the indicated array at the indicated index.
static double
getFlatnessSq(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)
Returns the square of the flatness, or maximum distance of a controlpoint from the line connecting the endpoints, of the quadratic 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 of this QuadCurve2D.
PathIterator
getPathIterator(AffineTransform at, double flatness)
Returns an iteration object that defines the boundary of the flattened shape of this QuadCurve2D.
abstract double
getX1()
Returns the x coordinate of the start point in double in 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 of this QuadCurve2D intersects the interior of a specified set of rectangular coordinates.
boolean
intersects(Rectangle2D r)
Tests if the shape of this QuadCurve2D intersects the interior of a specified Rectangle2D.
abstract void
setCurve(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)
Sets the location of the endpoints and controlpoint of this curve to the specified double coordinates.
void
setCurve(double[] coords, int offset)
Sets the location of the endpoints and controlpoints of this QuadCurve2D to the double coordinates at the specified offset in the specified array.
void
setCurve(Point2D p1, Point2D cp, Point2D p2)
Sets the location of the endpoints and controlpoint of this QuadCurve2D to the specified Point2D coordinates.
void
setCurve(Point2D[] pts, int offset)
Sets the location of the endpoints and controlpoints of this QuadCurve2D to the coordinates of the Point2D objects at the specified offset in the specified array.
void
setCurve(QuadCurve2D c)
Sets the location of the endpoints and controlpoint of this QuadCurve2D to the same as those in the specified QuadCurve2D.
static int
solveQuadratic(eqn[] )
Solves the quadratic 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
solveQuadratic(eqn[] , res[] )
Solves the quadratic whose coefficients are in the eqn array and places the non-complex roots into the res array, returning the number of roots.
void
subdivide(QuadCurve2D left, QuadCurve2D right)
Subdivides this QuadCurve2D and stores the resulting two subdivided curves into the left and right curve parameters.
static void
subdivide(QuadCurve2D src, QuadCurve2D left, QuadCurve2D right)
Subdivides the quadratic 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 quadratic curve specified by the coordinates stored in the src array at indices srcoff through srcoff + 5 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

QuadCurve2D

protected QuadCurve2D()
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 and with the same contents 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 of this QuadCurve2D.
Specified by:
contains in interface Shape
Parameters:
Returns:
true if the specified coordinate is inside the boundary of the shape of this QuadCurve2D; false otherwise.
Usages and Demos :

View More Examples of contains(double x,double y)
   1: import java.awt.Stroke;
   2: import java.awt.geom.QuadCurve2D;
   3: import java.util.List;
   4:         ...
   5:         p2 =  (Point)fPoints.get(1);
   6:     QuadCurve2D quadCurve = new QuadCurve2D.Float(p1.x, p1.y, fControlPoint.x, fControlPoint.y, p2.x, p2.y);
   7:         g2.draw(quadCurve);
   8:         ...
   9:     QuadCurve2D quadCurve = new QuadCurve2D.Float(p1.x, p1.y, fControlPoint.x, fControlPoint.y, p2.x, p2.y);
  10:     return quadCurve.contains(x,y);
  11:   }

View Full Code Here

contains

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

contains

public boolean contains(Point2D p)
Tests if a specified Point2D is inside the boundary of the shape of this QuadCurve2D.
Specified by:
contains in interface Shape
Parameters:
p - the specified Point2D
Returns:
true if the specified Point2D is inside the boundary of the shape of this QuadCurve2D.

contains

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

getBounds

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

getCtrlPt

public abstract Point2D getCtrlPt()
Returns the control point.
Returns:
a Point2D that is the control point of this Point2D.
Usages and Demos :

View More Examples of getCtrlPt()
   1: import java.awt.geom.Point2D;
   2: import java.awt.geom.QuadCurve2D;
   3: 
   4:         ...
   5: 
   6:   public QuadSegment(QuadCurve2D curve)
   7:   {
   8:         ...
   9:     P2 = curve.getP2();
  10:     this.cp = curve.getCtrlPt();
  11:   }
  12:         ...
  13: 
  14:     QuadCurve2D left = new QuadCurve2D.Double();

View Full Code Here

getCtrlX

public abstract double getCtrlX()
Returns the x coordinate of the control point in double precision.
Returns:
x coordinate the control point
Usages and Demos :

View More Examples of getCtrlX()
   1: import java.awt.geom.Point2D;
   2: import java.awt.geom.QuadCurve2D;
   3: 
   4:         ...
   5: 
   6:   public QuadSegment(QuadCurve2D curve)
   7:   {
   8:         ...
   9: 
  10:     QuadCurve2D left = new QuadCurve2D.Double();
  11:     QuadCurve2D right = new QuadCurve2D.Double();
  12:         ...
  13:     double[] n1 = normal(curve.getX1(), curve.getY1(), 
  14:                          curve.getCtrlX(), curve.getCtrlY());

View Full Code Here

getCtrlY

public abstract double getCtrlY()
Returns the y coordinate of the control point in double precision.
Returns:
the y coordinate of the control point.
Usages and Demos :

View More Examples of getCtrlY()
   1: import java.awt.geom.Point2D;
   2: import java.awt.geom.QuadCurve2D;
   3: 
   4:         ...
   5: 
   6:   public QuadSegment(QuadCurve2D curve)
   7:   {
   8:         ...
   9: 
  10:     QuadCurve2D left = new QuadCurve2D.Double();
  11:     QuadCurve2D right = new QuadCurve2D.Double();
  12:         ...
  13:     double[] n1 = normal(curve.getX1(), curve.getY1(), 
  14:                          curve.getCtrlX(), curve.getCtrlY());

View Full Code Here

getFlatness

public double getFlatness()
Returns the flatness, or maximum distance of a controlpoint from the line connecting the endpoints, of this QuadCurve2D.
Returns:
the flatness of this QuadCurve2D.

getFlatness

public static double getFlatness(coords[] ,
                                 int offset)
Returns the flatness, or maximum distance of a controlpoint from the line connecting the endpoints, of the quadratic curve specified by the controlpoints stored in the indicated array at the indicated index.
Parameters:
offset - the index into coords at which to start getting the coordinate values and assigning them to a quadratic curve
Returns:
the flatness of a quadratic curve defined by the specified array at the specified offset.

getFlatness

public static double getFlatness(double x1,
                                 double y1,
                                 double ctrlx,
                                 double ctrly,
                                 double x2,
                                 double y2)
Returns the flatness, or maximum distance of a controlpoint from the line connecting the endpoints, of the quadratic curve specified by the indicated controlpoints.
Parameters:
Returns:
the flatness of the quadratic curve defined by the specified coordinates.

getFlatnessSq

public double getFlatnessSq()
Returns the square of the flatness, or maximum distance of a controlpoint from the line connecting the endpoints, of this QuadCurve2D.
Returns:
the square of the flatness of this QuadCurve2D.

getFlatnessSq

public static double getFlatnessSq(coords[] ,
                                   int offset)
Returns the square of the flatness, or maximum distance of a controlpoint from the line connecting the endpoints, of the quadratic curve specified by the controlpoints stored in the indicated array at the indicated index.
Parameters:
offset - the index into coords at which to to start getting the values from the array and assigning them to a quadratic curve
Returns:
the flatness of the quadratic curve that is defined by the values in the specified array at the specified index.

getFlatnessSq

public static double getFlatnessSq(double x1,
                                   double y1,
                                   double ctrlx,
                                   double ctrly,
                                   double x2,
                                   double y2)
Returns the square of the flatness, or maximum distance of a controlpoint from the line connecting the endpoints, of the quadratic curve specified by the indicated controlpoints.
Parameters:
Returns:
the square of the flatness of the quadratic curve defined by the specified coordinates.

getP1

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

getP2

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

getPathIterator

public PathIterator getPathIterator(AffineTransform at)
Returns an iteration object that defines the boundary of the shape of this QuadCurve2D. The iterator for this class is not multi-threaded safe, which means that this QuadCurve2D class does not guarantee that modifications to the geometry of this QuadCurve2D 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 apply to the shape boundary
Returns:
a PathIterator object that defines the boundary of the shape.

getPathIterator

public PathIterator getPathIterator(AffineTransform at,
                                    double flatness)
Returns an iteration object that defines the boundary of the flattened shape of this QuadCurve2D. The iterator for this class is not multi-threaded safe, which means that this QuadCurve2D class does not guarantee that modifications to the geometry of this QuadCurve2D 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 apply to the boundary of the shape
flatness - the maximum distance that the control points for a subdivided curve can be with respect to a line connecting the endpoints of this curve before this curve is replaced by a straight line connecting the endpoints.
Returns:
a PathIterator object that defines the flattened boundary of the shape.

getX1

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

getX2

public abstract double getX2()
Returns the x coordinate of the end point in double precision.
Returns:
the x coordiante of the end point.
Usages and Demos :

View More Examples of getX2()
   1: import java.awt.geom.Point2D;
   2: import java.awt.geom.QuadCurve2D;
   3: 
   4:         ...
   5: 
   6:   public QuadSegment(QuadCurve2D curve)
   7:   {
   8:         ...
   9: 
  10:     QuadCurve2D left = new QuadCurve2D.Double();
  11:     QuadCurve2D right = new QuadCurve2D.Double();
  12:         ...
  13:     double[] n2 = normal(curve.getCtrlX(), curve.getCtrlY(),
  14:                          curve.getX2(), curve.getY2());

View Full Code Here

getY1

public abstract double getY1()
Returns the y coordinate of the start point in double precision.
Returns:
the y coordinate of the start point.
Usages and Demos :

View More Examples of getY1()
   1: import java.awt.geom.Point2D;
   2: import java.awt.geom.QuadCurve2D;
   3: 
   4:         ...
   5: 
   6:   public QuadSegment(QuadCurve2D curve)
   7:   {
   8:         ...
   9: 
  10:     QuadCurve2D left = new QuadCurve2D.Double();
  11:     QuadCurve2D right = new QuadCurve2D.Double();
  12:         ...
  13:   {
  14:     double[] n1 = normal(curve.getX1(), curve.getY1(), 

View Full Code Here

getY2

public abstract double getY2()
Returns the y coordinate of the end point in double precision.
Returns:
the y coordinate of the end point.
Usages and Demos :

View More Examples of getY2()
   1: import java.awt.geom.Point2D;
   2: import java.awt.geom.QuadCurve2D;
   3: 
   4:         ...
   5: 
   6:   public QuadSegment(QuadCurve2D curve)
   7:   {
   8:         ...
   9: 
  10:     QuadCurve2D left = new QuadCurve2D.Double();
  11:     QuadCurve2D right = new QuadCurve2D.Double();
  12:         ...
  13:     double[] n2 = normal(curve.getCtrlX(), curve.getCtrlY(),
  14:                          curve.getX2(), curve.getY2());

View Full Code Here

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Tests if the shape of this QuadCurve2D 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 of this QuadCurve2D intersects the interior of the specified set of rectangular coordinates; false otherwise.

intersects

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

setCurve

public abstract void setCurve(double x1,
                              double y1,
                              double ctrlx,
                              double ctrly,
                              double x2,
                              double y2)
Sets the location of the endpoints and controlpoint of this curve to the specified double coordinates.
Parameters:
Usages and Demos :

View More Examples of setCurve(double x1,double y1,double ctrlx,double ctrly,double x2,double y2)
   1: import java.awt.geom.AffineTransform;
   2: import java.awt.geom.QuadCurve2D;
   3: import java.awt.Color;
   4:         ...
   5: 
   6:   private QuadCurve2D spline_ = new QuadCurve2D.Double();
   7: 
   8:   private Map<String,Object> pdest_=null;

View Full Code Here

setCurve

public void setCurve(double[] coords,
                     int offset)
Sets the location of the endpoints and controlpoints of this QuadCurve2D to the double coordinates at the specified offset in the specified array.
Parameters:
coords - the array containing coordinate values
offset - the index into the array from which to start getting the coordinate values and assigning them to this QuadCurve2D

setCurve

public void setCurve(Point2D p1,
                     Point2D cp,
                     Point2D p2)
Sets the location of the endpoints and controlpoint of this QuadCurve2D to the specified Point2D coordinates.
Parameters:
p1 - the starting point
cp - the control point
p2 - the ending point

setCurve

public void setCurve(Point2D[] pts,
                     int offset)
Sets the location of the endpoints and controlpoints of this QuadCurve2D to the coordinates of the Point2D objects at the specified offset in the specified array.
Parameters:
pts - an array containing Point2D that define coordinate values
offset - the index into pts at which to start getting the coordinate values and assigning them to this QuadCurve2D

setCurve

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

solveQuadratic

public static int solveQuadratic(eqn[] )
Solves the quadratic whose coefficients are in the eqn array and places the non-complex roots back into the same array, returning the number of roots. The quadratic solved is represented by the equation:
     eqn = {C, B, A};
     ax^2 + bx + c = 0
 
A return value of -1 is used to distinguish a constant equation, which 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
Usages and Demos :

View More Examples of solveQuadratic(eqn[] )
   1: import java.awt.geom.Point2D;
   2: import java.awt.geom.QuadCurve2D;
   3: import java.awt.geom.Rectangle2D;
   4:         ...
   5:         double [] eqn = { c0, c1-2*c0, c2-c1+c0 };
   6:         int roots = QuadCurve2D.solveQuadratic(eqn);
   7:         for (int r=0; r<roots; r++) {
   8:             double tv = eqn[r];
   9:             if ((tv <= 0) || (tv >= 1)) continue;

View Full Code Here

solveQuadratic

public static int solveQuadratic(eqn[] ,
                                 res[] )
Solves the quadratic whose coefficients are in the eqn array and places the non-complex roots into the res array, returning the number of roots. The quadratic solved is represented by the equation:
     eqn = {C, B, A};
     ax^2 + bx + c = 0
 
A return value of -1 is used to distinguish a constant equation, which 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.
Usages and Demos :

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

View Full Code Here

subdivide

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

subdivide

public static void subdivide(QuadCurve2D src,
                             QuadCurve2D left,
                             QuadCurve2D right)
Subdivides the quadratic 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 can be the same as the src object or null.
Parameters:
src - the quadratic curve to be subdivided
left - the QuadCurve2D object for storing the left or first half of the subdivided curve
right - the QuadCurve2D 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 quadratic curve specified by the coordinates stored in the src array at indices srcoff through srcoff + 5 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 can be null or a reference to the same array and offset 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 that rightoff equals leftoff + 4 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