public class Polygon extends java.lang.Object implements IShape
PrecisionUtils) to compensate for rounding effects.| Constructor and Description |
|---|
Polygon(double... coordinates)
Constructs a new
Polygon from a even-numbered sequence of
coordinates. |
Polygon(Point... points)
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
clone()
Overridden with public visibility as recommended within
Cloneable
. |
boolean |
contains(double x,
double y)
Checks whether the point that is represented by its x- and y-coordinates
is contained within this
Polygon. |
boolean |
contains(IGeometry g)
|
boolean |
contains(Line line)
|
boolean |
contains(Point p)
|
boolean |
contains(Polygon p)
|
boolean |
contains(Polyline p)
|
boolean |
contains(Rectangle r)
|
boolean |
equals(java.lang.Object o) |
boolean |
equals(Point[] points)
Checks whether this
Polygon and the one that is indirectly given
via the given array of points are regarded to be equal. |
double |
getArea()
Computes the area of this
Polygon. |
Rectangle |
getBounds()
|
Point |
getCentroid()
Computes the centroid of this
AbstractPointListBasedGeometry. |
double[] |
getCoordinates()
Returns a double array which represents the sequence of coordinates of
the
Points that make up this
AbstractPointListBasedGeometry. |
Polygon |
getCopy()
Returns a copy of this
Polygon, which is made up by the same
points. |
Polyline |
getOutline()
|
Line[] |
getOutlineSegments()
|
Point[] |
getPoints()
Returns a copy of the
Points that make up this
AbstractPointListBasedGeometry. |
T |
getRotatedCCW(Angle alpha)
|
T |
getRotatedCCW(Angle angle,
double cx,
double cy)
|
T |
getRotatedCCW(Angle alpha,
Point center)
|
T |
getRotatedCW(Angle alpha)
|
T |
getRotatedCW(Angle angle,
double cx,
double cy)
|
T |
getRotatedCW(Angle alpha,
Point center)
|
T |
getScaled(double factor)
Scales a copy of the calling object by the given factor relative to its
center
Point. |
T |
getScaled(double factorX,
double factorY)
Scales a copy of the calling object by the given factors relative to its
center
Point. |
T |
getScaled(double factor,
double cx,
double cy)
Scales a copy of the calling object by the given factor relative to the
given center
Point (cx, cy). |
T |
getScaled(double fx,
double fy,
double cx,
double cy)
Scales a copy of the calling object by the given factors relative to the
given center
Point (cx, cy). |
T |
getScaled(double factorX,
double factorY,
Point center)
Scales a copy of the calling object by the given factors relative to the
given center
Point. |
T |
getScaled(double factor,
Point center)
Scales a copy of the calling object by the given factor relative to the
given center
Point. |
double |
getSignedArea()
Computes the signed area of this
Polygon. |
Polygon |
getTransformed(AffineTransform t)
|
T |
getTranslated(double dx,
double dy)
Translates a copy of this object by the given values in x and y
direction.
|
T |
getTranslated(Point pt)
Translates a copy of this object by the given
Point. |
Polygon[] |
getTriangulation()
Naive, recursive ear-clipping algorithm to triangulate this simple,
planar
Polygon. |
int |
hashCode() |
T |
rotateCCW(Angle alpha)
Rotates this
AbstractPointListBasedGeometry counter-clockwise
(CCW) by the given Angle around its centroid (see
getCentroid()). |
T |
rotateCCW(Angle alpha,
double cx,
double cy)
|
T |
rotateCCW(Angle alpha,
Point center)
|
T |
rotateCW(Angle alpha)
Rotates this
AbstractPointListBasedGeometry clockwise (CW) by the
given Angle around its centroid (see getCentroid()). |
T |
rotateCW(Angle alpha,
double cx,
double cy)
|
T |
rotateCW(Angle alpha,
Point center)
|
T |
scale(double factor)
Scales the calling object by the given factor relative to its center
Point. |
T |
scale(double fx,
double fy)
Scales the calling object by the given factors relative to the given
center
Point. |
T |
scale(double factor,
double cx,
double cy)
Scales the calling object by the given factor relative to the given
center
Point (cx, cy). |
T |
scale(double fx,
double fy,
double cx,
double cy)
Scales the calling object by the given factors relative to the given
center
Point (cx, cy). |
T |
scale(double fx,
double fy,
Point center)
Scales the calling object by the given factors relative to the given
center
Point. |
T |
scale(double factor,
Point center)
Scales the calling object by the given factor relative to the given
center
Point. |
Path |
toPath()
|
java.lang.String |
toString() |
boolean |
touches(IGeometry g)
|
T |
translate(double dx,
double dy)
Translates the object by the given values in x and y direction.
|
T |
translate(Point p)
Translates the object by the given
Point. |
public Polygon(double... coordinates)
Polygon from a even-numbered sequence of
coordinates.coordinates - an alternating, even-numbered sequence of x and y coordinates,
representing the Points from which the Polygon
is to be createdPolygon(Point...)public Polygon(Point... points)
Polygon from the given sequence of Point
s. The Polygon that is created will be automatically closed, i.e.
it will not only contain a segment between succeeding points of the
sequence but as well back from the last to the first point.points - a sequence of points, from which the Polygon is to be
created.public boolean contains(double x,
double y)
Polygon.x - the x-coordinate of the point to testy - the y-coordinate of the point to testtrue if the point represented by its coordinates if
contained within this Polygon, false
otherwisepublic boolean contains(Line line)
public boolean contains(Polygon p)
public boolean contains(Polyline p)
p - The Polyline to test for containment.public boolean contains(Rectangle r)
public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic boolean equals(Point[] points)
Polygon and the one that is indirectly given
via the given array of points are regarded to be equal. The
Polygons will be regarded equal, if they are characterized by the
same segments. As a Polygon is always regarded to be closed, the
list of points may not have to correspond in each index value, they may
also be shifted by a certain offset. Moreover, the vertices of two
equally Polygons may be reverted in order.public double getArea()
Polygon.Polygonpublic Polygon getCopy()
Polygon, which is made up by the same
points.public Polyline getOutline()
IShapegetOutline in interface IShapeICurve representing this IShape's outline.public Line[] getOutlineSegments()
Lines, representing the segments that are
obtained by linking each two successive point of this Polygon
(including the last and the first one).getOutlineSegments in interface IShapeLines, representing the segments that make up
this Polygonpublic double getSignedArea()
Polygon. The sign of the area is
negative for counter clockwise ordered vertices. It is positive for
clockwise ordered vertices.Polygonpublic Polygon getTransformed(AffineTransform t)
Path
representation of this IGeometry. Subclasses may override this
method to return a more specific representation.getTransformed in interface IGeometrygetTransformed in interface IShapet - The AffineTransform to be appliedPath representation of this
IGeometryIGeometry.getTransformed(AffineTransform)public Polygon[] getTriangulation()
Polygon.Polygons (triangles)public Path toPath()
IGeometrytoPath in interface IGeometryPath representation for this IGeometry.IGeometry.toPath()public java.lang.String toString()
toString in class java.lang.Objectpublic Point getCentroid()
AbstractPointListBasedGeometry. The
centroid is the "center of gravity", i.e. assuming a Polygon is
spanned by the Points of this
AbstractPointListBasedGeometry and it is made of a material of
constant density, then it is in a balanced state, if you put it on a pin
that is placed exactly on its centroid.Point (or centroid) of this
AbstractPointListBasedGeometrypublic final double[] getCoordinates()
Points that make up this
AbstractPointListBasedGeometry.AbstractPointListBasedGeometry's pointspublic final Point[] getPoints()
Points that make up this
AbstractPointListBasedGeometry.public T getRotatedCCW(Angle alpha)
IRotatableAngle counter-clock-wise
(CCW) around its center Point. Does not necessarily return an
object of the same type.getRotatedCCW in interface IRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>alpha - rotation AngleIGeometry representing the result of the rotationpublic T getRotatedCCW(Angle angle, double cx, double cy)
IRotatableAngle
counter-clock-wise (CCW) around the specified center Point (cx,
cy). Does not necessarily return an object of the same type.getRotatedCCW in interface IRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>angle - rotation Anglecx - x-coordinate of the relative Point for the rotationcy - y-coordinate of the relative Point for the rotationIGeometry representing the result of the rotationpublic T getRotatedCCW(Angle alpha, Point center)
IRotatableAngle
counter-clock-wise (CCW) around the specified center Point. Does
not necessarily return an object of the same type.getRotatedCCW in interface IRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>alpha - rotation Anglecenter - relative Point for the rotationIGeometry representing the result of the rotationpublic T getRotatedCW(Angle alpha)
IRotatableAngle clock-wise (CW)
around its center Point. Does not necessarily return an object of
the same type.getRotatedCW in interface IRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>alpha - rotation AngleIGeometry representing the result of the rotationpublic T getRotatedCW(Angle angle, double cx, double cy)
IRotatableAngle clock-wise (CW)
around the specified center Point (cx, cy). Does not necessarily
return an object of the same type.getRotatedCW in interface IRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>angle - rotation Anglecx - x-coordinate of the relative Point for the rotationcy - y-coordinate of the relative Point for the rotationIGeometry representing the result of the rotationpublic T getRotatedCW(Angle alpha, Point center)
IRotatableAngle clock-wise (CW)
around the specified center Point. Does not necessarily return an
object of the same type.getRotatedCW in interface IRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>alpha - rotation Anglecenter - relative Point for the rotationIGeometry representing the result of the rotationpublic T getScaled(double factor)
IScalablePoint.public T getScaled(double factorX,
double factorY)
IScalablePoint.public T getScaled(double factor,
double cx,
double cy)
IScalablePoint (cx, cy).getScaled in interface IScalable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>factor - scale-factorcx - x-coordinate of the relative Point for the scalingcy - y-coordinate of the relative Point for the scalingpublic T getScaled(double fx,
double fy,
double cx,
double cy)
IScalablePoint (cx, cy).getScaled in interface IScalable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>fx - x-scale-factorfy - y-scale-factorcx - x-coordinate of the relative Point for the scalingcy - y-coordinate of the relative Point for the scalingpublic T getScaled(double factorX,
double factorY,
Point center)
IScalablePoint.public T getScaled(double factor,
Point center)
IScalablePoint.public T getTranslated(double dx,
double dy)
ITranslatablegetTranslated in interface ITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>dx - x-translationdy - y-translationpublic T getTranslated(Point pt)
ITranslatablePoint.getTranslated in interface ITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>pt - translation Pointpublic T rotateCCW(Angle alpha)
AbstractPointListBasedGeometry counter-clockwise
(CCW) by the given Angle around its centroid (see
getCentroid()).alpha - the rotation Anglethis for conveniencerotateCCW(Angle, Point)public T rotateCCW(Angle alpha, double cx, double cy)
AbstractPointListBasedGeometry counter-clockwise
(CCW) by the given Angle around the Point specified by
the passed-in x and y coordinates.alpha - the rotation Anglecx - the x coordinate of the Point to rotate aroundcy - the y coordinate of the Point to rotate aroundthis for conveniencerotateCCW(Angle, Point)public T rotateCW(Angle alpha)
AbstractPointListBasedGeometry clockwise (CW) by the
given Angle around its centroid (see getCentroid()).alpha - the rotation Anglethis for conveniencerotateCW(Angle, Point)public T rotateCW(Angle alpha, double cx, double cy)
AbstractPointListBasedGeometry clockwise (CW) by the
given Angle around the Point specified by the passed-in x
and y coordinates.alpha - the rotation Anglecx - the x coordinate of the Point to rotate aroundcy - the y coordinate of the Point to rotate aroundthis for conveniencerotateCW(Angle, Point)public T scale(double factor)
IScalablePoint.public T scale(double fx,
double fy)
IScalablePoint.public T scale(double factor,
double cx,
double cy)
IScalablePoint (cx, cy).public T scale(double fx,
double fy,
double cx,
double cy)
IScalablePoint (cx, cy).scale in interface IScalable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>fx - x-scale-factorfy - y-scale-factorcx - x-coordinate of the relative Point for the scalingcy - y-coordinate of the relative Point for the scalingthis for conveniencepublic T scale(double fx,
double fy,
Point center)
IScalablePoint.public T scale(double factor,
Point center)
IScalablePoint.public T translate(double dx,
double dy)
ITranslatabletranslate in interface ITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>dx - x-translationdy - y-translationthis for conveniencepublic T translate(Point p)
ITranslatablePoint.translate in interface ITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>p - translation Pointthis for conveniencepublic java.lang.Object clone()
Cloneable
.clone in class java.lang.Objectpublic final int hashCode()
hashCode in class java.lang.ObjectObject.hashCode()Copyright (c) 2014 itemis AG, and others. All rights reserved.