com.partnersoft.geometry.xy
Class XyRegularPolygon

java.lang.Object
  extended by com.partnersoft.geometry.xy.XyRegularPolygon
All Implemented Interfaces:
Immutable, XyArea<XyRegularPolygon>, XyShape<XyRegularPolygon>, java.lang.Iterable<XyPoint>

public class XyRegularPolygon
extends java.lang.Object
implements XyArea<XyRegularPolygon>

A regular polygon has equal-length sides and equal-size angles. It can have any number of sides greater than two. We allow it to be placed at any desired center point, radius, and rotation.

Regular polygons are also referred to as n-gons (e.g. 5-gon, 8-gon, etc.).

Copyright 2007 Partner Software, Inc.

Version:
$Id: XyRegularPolygon.java 1195 2008-02-18 22:37:30Z paul $
Author:
Paul Reavis, Rich Stepanski, Richard Fay

Constructor Summary
XyRegularPolygon(XyPoint center, double radius, int pointCount)
           
XyRegularPolygon(XyPoint center, double radius, int pointCount, XyRotation rotation)
           
 
Method Summary
 boolean contains(XyPoint point)
          Tests if a point is inside this area.
 boolean equals(java.lang.Object nother)
           
 double getArea()
          Returns the 2-dimensional area covered by this...
 XyBounds getBounds()
          Returns an XyBounds object representing the rectangular extents of this shape.
 double getPerimeter()
          Returns the total length of the lines and/or curves bounding the area.
 java.util.Iterator<XyPoint> iterator()
           
 XyRegularPolygon scaledBy(double factor)
          Return a scaled version of the shape by multiplying all coordinates by the given factor in both dimensions.
 XyPolygon toPolygon()
          Same as XyArea.toPolygon(XyAngle) with a default angle granularity of 1/60 circle (1 degree, pi/30 radians).
 XyPolygon toPolygon(XyAngle granularity)
          Converts this area to a polygon which approximates it in some fashion.
 XyPolyline toPolyline()
           
 java.lang.String toString()
           
 XyShape transformedBy(XyTransform transform)
          Transform the shape using the given transform.
 XyRegularPolygon translatedBy(double offsetX, double offsetY)
          Translate the shape by adding all coordinates to the given x and y offsets.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XyRegularPolygon

public XyRegularPolygon(XyPoint center,
                        double radius,
                        int pointCount)

XyRegularPolygon

public XyRegularPolygon(XyPoint center,
                        double radius,
                        int pointCount,
                        XyRotation rotation)
Method Detail

toPolyline

public XyPolyline toPolyline()

scaledBy

public XyRegularPolygon scaledBy(double factor)
Description copied from interface: XyShape
Return a scaled version of the shape by multiplying all coordinates by the given factor in both dimensions. This resulting shape must be of the same class as the original.

Specified by:
scaledBy in interface XyShape<XyRegularPolygon>
Parameters:
factor - scaling factor
Returns:
scaled result

translatedBy

public XyRegularPolygon translatedBy(double offsetX,
                                     double offsetY)
Description copied from interface: XyShape
Translate the shape by adding all coordinates to the given x and y offsets. The resulting shape must be of the same class as the original.

Specified by:
translatedBy in interface XyShape<XyRegularPolygon>
Parameters:
offsetX - offset for the x dimension
offsetY - offset for the y dimension
Returns:
offset result

transformedBy

public XyShape transformedBy(XyTransform transform)
Description copied from interface: XyShape
Transform the shape using the given transform. Due to potential distortion the result may be a different type of shape than this one.

Specified by:
transformedBy in interface XyShape<XyRegularPolygon>
Parameters:
transform - affine transform to apply.
Returns:
transformed result

contains

public boolean contains(XyPoint point)
Description copied from interface: XyArea
Tests if a point is inside this area.

Specified by:
contains in interface XyArea<XyRegularPolygon>
Parameters:
point - point to test for containment

toPolygon

public XyPolygon toPolygon()
Description copied from interface: XyArea
Same as XyArea.toPolygon(XyAngle) with a default angle granularity of 1/60 circle (1 degree, pi/30 radians).

Specified by:
toPolygon in interface XyArea<XyRegularPolygon>

toPolygon

public XyPolygon toPolygon(XyAngle granularity)
Description copied from interface: XyArea
Converts this area to a polygon which approximates it in some fashion. For example, a circle can be converted to a polygon with enough sides to roughly approximate its shape. Areas consisting of linked line segments can be represented exactly.

The angle parameter allows a certain level of control of the output. Essentially it dictates the minimum angular granularity used to approximate curved paths. For example, a circle would be turned into a polygon by placing points around the circle, separated by the given angle.

Specified by:
toPolygon in interface XyArea<XyRegularPolygon>

getArea

public double getArea()
Description copied from interface: XyArea
Returns the 2-dimensional area covered by this... area.

Specified by:
getArea in interface XyArea<XyRegularPolygon>
Returns:
geometric area of this shape

getPerimeter

public double getPerimeter()
Description copied from interface: XyArea
Returns the total length of the lines and/or curves bounding the area.

Specified by:
getPerimeter in interface XyArea<XyRegularPolygon>
Returns:
geometric perimeter of this shape

getBounds

public XyBounds getBounds()
Description copied from interface: XyShape
Returns an XyBounds object representing the rectangular extents of this shape.

Specified by:
getBounds in interface XyShape<XyRegularPolygon>

iterator

public java.util.Iterator<XyPoint> iterator()
Specified by:
iterator in interface java.lang.Iterable<XyPoint>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object nother)
Overrides:
equals in class java.lang.Object