java.awt.geom
Class Arc2D

java.lang.Object
  extended by java.awt.geom.RectangularShape
      extended by java.awt.geom.Arc2D
All Implemented Interfaces:
Shape, Cloneable
Direct Known Subclasses:
Arc2D.Double, Arc2D.Float

public abstract class Arc2D
extends RectangularShape

This class represents all arcs (segments of an ellipse in 2-D space). The arcs are defined by starting angle and extent (arc length) in degrees, as opposed to radians (like the rest of Java), and can be open, chorded, or wedge shaped. The angles are skewed according to the ellipse, so that 45 degrees always points to the upper right corner (positive x, negative y) of the bounding rectangle. A positive extent draws a counterclockwise arc, and while the angle can be any value, the path iterator only traverses the first 360 degrees. Storage is up to the subclasses.

Since:
1.2

Nested Class Summary
static class Arc2D.Double
          This class implements an arc in double precision.
static class Arc2D.Float
          This class implements an arc in float precision.
 
Field Summary
static int CHORD
          A closed arc with a single segment connecting the endpoints (a chord).
static int OPEN
          An open arc, with no segment connecting the endpoints.
static int PIE
          A closed arc with two segments, one from each endpoint, meeting at the center of the ellipse.
 
Constructor Summary
protected Arc2D(int type)
          Create a new arc, with the specified closure type.
 
Method Summary
 boolean contains(double x, double y)
          Determines if the arc contains the given point.
 boolean contains(double x, double y, double w, double h)
          Tests if a given rectangle is contained in the area of the arc.
 boolean contains(Rectangle2D r)
          Tests if a given rectangle is contained in the area of the arc.
 boolean containsAngle(double a)
          Tests if the given angle, in degrees, is included in the arc.
abstract  double getAngleExtent()
          Get the extent angle of the arc in degrees.
abstract  double getAngleStart()
          Get the starting angle of the arc in degrees.
 int getArcType()
          Return the closure type of the arc.
 Rectangle2D getBounds2D()
          Gets the bounds of the arc.
 Point2D getEndPoint()
          Returns the ending point of the arc.
 PathIterator getPathIterator(AffineTransform at)
          Returns an iterator over this arc, with an optional transformation.
 Point2D getStartPoint()
          Returns the starting point of the arc.
 boolean intersects(double x, double y, double w, double h)
          Tests if a given rectangle intersects the area of the arc.
protected abstract  Rectangle2D makeBounds(double x, double y, double w, double h)
          Construct a bounding box in a precision appropriate for the subclass.
abstract  void setAngleExtent(double extent)
          Set the extent, in degrees.
 void setAngles(double x1, double y1, double x2, double y2)
          Sets the starting and extent angles to those of the given points relative to the center of the arc.
 void setAngles(Point2D p1, Point2D p2)
          Sets the starting and extent angles to those of the given points relative to the center of the arc.
abstract  void setAngleStart(double start)
          Set the start, in degrees.
 void setAngleStart(Point2D p)
          Sets the starting angle to the angle of the given point relative to the center of the arc.
 void setArc(Arc2D a)
          Set the parameters of the arc from the given one.
abstract  void setArc(double x, double y, double w, double h, double start, double extent, int type)
          Set the parameters of the arc.
 void setArc(Point2D p, Dimension2D d, double start, double extent, int type)
          Set the parameters of the arc.
 void setArc(Rectangle2D r, double start, double extent, int type)
          Set the parameters of the arc.
 void setArcByCenter(double x, double y, double r, double start, double extent, int type)
          Set the parameters of the arc.
 void setArcByTangent(Point2D p1, Point2D p2, Point2D p3, double r)
          Sets the parameters of the arc by finding the tangents of two lines, and using the specified radius.
 void setArcType(int type)
          Set the closure type of this arc.
 void setFrame(double x, double y, double w, double h)
          Sets the location and bounds of the ellipse of which this arc is a part.
 
Methods inherited from class java.awt.geom.RectangularShape
clone, contains, getBounds, getCenterX, getCenterY, getFrame, getHeight, getMaxX, getMaxY, getMinX, getMinY, getPathIterator, getWidth, getX, getY, intersects, isEmpty, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPEN

public static final int OPEN
An open arc, with no segment connecting the endpoints. This type of arc still contains the same points as a chorded version.

See Also:
Constant Field Values

CHORD

public static final int CHORD
A closed arc with a single segment connecting the endpoints (a chord).

See Also:
Constant Field Values

PIE

public static final int PIE
A closed arc with two segments, one from each endpoint, meeting at the center of the ellipse.

See Also:
Constant Field Values
Constructor Detail

Arc2D

protected Arc2D(int type)
Create a new arc, with the specified closure type.

Parameters:
type - one of OPEN, CHORD, or PIE.
Throws:
IllegalArgumentException - if type is invalid
Method Detail

getAngleStart

public abstract double getAngleStart()
Get the starting angle of the arc in degrees.

Returns:
the starting angle
See Also:
setAngleStart(double)

getAngleExtent

public abstract double getAngleExtent()
Get the extent angle of the arc in degrees.

Returns:
the extent angle
See Also:
setAngleExtent(double)

getArcType

public int getArcType()
Return the closure type of the arc.

Returns:
the closure type
See Also:
OPEN, CHORD, PIE, setArcType(int)

getStartPoint

public Point2D getStartPoint()
Returns the starting point of the arc.

Returns:
the start point

getEndPoint

public Point2D getEndPoint()
Returns the ending point of the arc.

Returns:
the end point

setArc

public abstract void setArc(double x,
                            double y,
                            double w,
                            double h,
                            double start,
                            double extent,
                            int type)
Set the parameters of the arc. The angles are in degrees, and a positive extent sweeps counterclockwise (from the positive x-axis to the negative y-axis).

Parameters:
x - the new x coordinate of the upper left of the bounding box
y - the new y coordinate of the upper left of the bounding box
w - the new width of the bounding box
h - the new height of the bounding box
start - the start angle, in degrees
extent - the arc extent, in degrees
type - one of OPEN, CHORD, or PIE
Throws:
IllegalArgumentException - if type is invalid

setArc

public void setArc(Point2D p,
                   Dimension2D d,
                   double start,
                   double extent,
                   int type)
Set the parameters of the arc. The angles are in degrees, and a positive extent sweeps counterclockwise (from the positive x-axis to the negative y-axis).

Parameters:
p - the upper left point of the bounding box
d - the dimensions of the bounding box
start - the start angle, in degrees
extent - the arc extent, in degrees
type - one of OPEN, CHORD, or PIE
Throws:
IllegalArgumentException - if type is invalid
NullPointerException - if p or d is null

setArc

public void setArc(Rectangle2D r,
                   double start,
                   double extent,
                   int type)
Set the parameters of the arc. The angles are in degrees, and a positive extent sweeps counterclockwise (from the positive x-axis to the negative y-axis).

Parameters:
r - the new bounding box
start - the start angle, in degrees
extent - the arc extent, in degrees
type - one of OPEN, CHORD, or PIE
Throws:
IllegalArgumentException - if type is invalid
NullPointerException - if r is null

setArc

public void setArc(Arc2D a)
Set the parameters of the arc from the given one.

Parameters:
a - the arc to copy
Throws:
NullPointerException - if a is null

setArcByCenter

public void setArcByCenter(double x,
                           double y,
                           double r,
                           double start,
                           double extent,
                           int type)
Set the parameters of the arc. The angles are in degrees, and a positive extent sweeps counterclockwise (from the positive x-axis to the negative y-axis). This controls the center point and radius, so the arc will be circular.

Parameters:
x - the x coordinate of the center of the circle
y - the y coordinate of the center of the circle
r - the radius of the circle
start - the start angle, in degrees
extent - the arc extent, in degrees
type - one of OPEN, CHORD, or PIE
Throws:
IllegalArgumentException - if type is invalid

setArcByTangent

public void setArcByTangent(Point2D p1,
                            Point2D p2,
                            Point2D p3,
                            double r)
Sets the parameters of the arc by finding the tangents of two lines, and using the specified radius. The arc will be circular, will begin on the tangent point of the line extending from p1 to p2, and will end on the tangent point of the line extending from p2 to p3. XXX What happens if the points are colinear, or the radius negative?

Parameters:
p1 - the first point
p2 - the tangent line intersection point
p3 - the third point
r - the radius of the arc
Throws:
NullPointerException - if any point is null

setAngleStart

public abstract void setAngleStart(double start)
Set the start, in degrees.

Parameters:
start - the new start angle
See Also:
getAngleStart()

setAngleExtent

public abstract void setAngleExtent(double extent)
Set the extent, in degrees.

Parameters:
extent - the new extent angle
See Also:
getAngleExtent()

setAngleStart

public void setAngleStart(Point2D p)
Sets the starting angle to the angle of the given point relative to the center of the arc. The extent remains constant; in other words, this rotates the arc.

Parameters:
p - the new start point
Throws:
NullPointerException - if p is null
See Also:
getStartPoint(), getAngleStart()

setAngles

public void setAngles(double x1,
                      double y1,
                      double x2,
                      double y2)
Sets the starting and extent angles to those of the given points relative to the center of the arc. The arc will be non-empty, and will extend counterclockwise.

Parameters:
x1 - the first x coordinate
y1 - the first y coordinate
x2 - the second x coordinate
y2 - the second y coordinate
See Also:
setAngleStart(Point2D)

setAngles

public void setAngles(Point2D p1,
                      Point2D p2)
Sets the starting and extent angles to those of the given points relative to the center of the arc. The arc will be non-empty, and will extend counterclockwise.

Parameters:
p1 - the first point
p2 - the second point
Throws:
NullPointerException - if either point is null
See Also:
setAngleStart(Point2D)

setArcType

public void setArcType(int type)
Set the closure type of this arc.

Parameters:
type - one of OPEN, CHORD, or PIE
Throws:
IllegalArgumentException - if type is invalid
See Also:
getArcType()

setFrame

public void setFrame(double x,
                     double y,
                     double w,
                     double h)
Sets the location and bounds of the ellipse of which this arc is a part.

Specified by:
setFrame in class RectangularShape
Parameters:
x - the new x coordinate
y - the new y coordinate
w - the new width
h - the new height
See Also:
RectangularShape.getFrame()

getBounds2D

public Rectangle2D getBounds2D()
Gets the bounds of the arc. This is much tighter than getBounds, as it takes into consideration the start and end angles, and the center point of a pie wedge, rather than just the overall ellipse.

Returns:
the bounds of the arc
See Also:
RectangularShape.getBounds()

makeBounds

protected abstract Rectangle2D makeBounds(double x,
                                          double y,
                                          double w,
                                          double h)
Construct a bounding box in a precision appropriate for the subclass.

Parameters:
x - the x coordinate
y - the y coordinate
w - the width
h - the height
Returns:
the rectangle for use in getBounds2D

containsAngle

public boolean containsAngle(double a)
Tests if the given angle, in degrees, is included in the arc. All angles are normalized to be between 0 and 360 degrees.

Parameters:
a - the angle to test
Returns:
true if it is contained

contains

public boolean contains(double x,
                        double y)
Determines if the arc contains the given point. If the bounding box is empty, then this will return false. The area considered 'inside' an arc of type OPEN is the same as the area inside an equivalent filled CHORD-type arc. The area considered 'inside' a CHORD-type arc is the same as the filled area.

Parameters:
x - the x coordinate to test
y - the y coordinate to test
Returns:
true if the point is inside the arc

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Tests if a given rectangle intersects the area of the arc. For a definition of the 'inside' area, see the contains() method.

Parameters:
x - the x coordinate of the rectangle
y - the y coordinate of the rectangle
w - the width of the rectangle
h - the height of the rectangle
Returns:
true if the two shapes share common points
See Also:
contains(double, double)

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Tests if a given rectangle is contained in the area of the arc.

Parameters:
x - the x coordinate of the rectangle
y - the y coordinate of the rectangle
w - the width of the rectangle
h - the height of the rectangle
Returns:
true if the arc contains the rectangle
See Also:
Area

contains

public boolean contains(Rectangle2D r)
Tests if a given rectangle is contained in the area of the arc.

Specified by:
contains in interface Shape
Overrides:
contains in class RectangularShape
Parameters:
r - the rectangle
Returns:
true if the arc contains the rectangle
See Also:
Shape.contains(double, double, double, double)

getPathIterator

public PathIterator getPathIterator(AffineTransform at)
Returns an iterator over this arc, with an optional transformation. This iterator is threadsafe, so future modifications to the arc do not affect the iteration.

Parameters:
at - the transformation, or null
Returns:
a path iterator