This class represents a polygon as a list of vertices. It only provides the
abstract geometric representation, and methods to alter or decompose them.
To actually draw a polygon on the screen, use the PolygonShape
class.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Polygon()
Initializes a new, empty polygon.
| ||||||||||
|
Polygon(float... xyArray)
Initializes a new polygon from a list of vertices.
| ||||||||||
|
Polygon(Polygon source)
Initializes a new polygon that is a copy of the specified polygon.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void
|
add(int index, PointF point)
Inserts a vertex at the specified location in the polygon.
| ||||||||||
boolean
|
add(PointF point)
Adds a vertex to the end of the polygon.
| ||||||||||
void
|
addFrom(Polygon source, int start, int end)
Adds a sequence of vertices from another polygon to the end of this one.
| ||||||||||
float
|
area()
Gets the area of the polygon.
| ||||||||||
PointF
|
centroid()
Gets the centroid of the polygon.
| ||||||||||
List<Polygon>
|
convexDecomposition()
Computes the convex decomposition of this polygon, with the added restriction that each polygon in the decomposition contains no more than eight vertices. | ||||||||||
PointF
|
get(int index)
Gets the vertex at the specified index.
| ||||||||||
Iterator<PointF>
|
iterator()
Gets an iterator that can be used to iterate over the vertices in the
polygon.
| ||||||||||
PointF
|
remove(int index)
Removes the vertex at the specified index from the polygon.
| ||||||||||
PointF
|
set(int index, PointF point)
Replaces the vertex at the specified index with a different point.
| ||||||||||
Polygon
|
simplify(float tolerance)
Computes a simplified version of this polygon, by trying to eliminate
vertices that are within a specified tolerance if the perpendicular
distance is measured between them and a hypothetical line between two
nearby vertices.
| ||||||||||
int
|
size()
Gets the number of vertices in this polygon.
| ||||||||||
Polygon
|
slice(int start, int end)
|
Methods inherited from
class
java.lang.Object
| |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Object
|
clone()
| ||||||||||
boolean
|
equals(Object arg0)
| ||||||||||
void
|
finalize()
| ||||||||||
final
Class<?>
|
getClass()
| ||||||||||
int
|
hashCode()
| ||||||||||
final
void
|
notify()
| ||||||||||
final
void
|
notifyAll()
| ||||||||||
String
|
toString()
| ||||||||||
final
void
|
wait()
| ||||||||||
final
void
|
wait(long arg0, int arg1)
| ||||||||||
final
void
|
wait(long arg0)
|
Methods inherited from
interface
java.lang.Iterable
| |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
abstract
Iterator<T>
|
iterator()
|
Initializes a new, empty polygon.
Initializes a new polygon from a list of vertices. The polygon is automatically closed.
Initializes a new polygon that is a copy of the specified polygon.
Inserts a vertex at the specified location in the polygon.
Adds a vertex to the end of the polygon.
always true
Adds a sequence of vertices from another polygon to the end of this one.
Gets the area of the polygon.
the area of the polygon
Gets the centroid of the polygon.
the centroid of the polygon
Computes the convex decomposition of this polygon, with the added restriction that each polygon in the decomposition contains no more than eight vertices.
The result is cached once it is computed, so multiple calls to this method will not incur performance penalties unless the vertices in the polygon change.
the List
of polygons that make up the receiver's convex
decomposition
Gets the vertex at the specified index. This accessor is circular; negative indices and indices greater than the size of the polygon are wrapped appropriately.
the vertex at the specified index
Gets an iterator that can be used to iterate over the vertices in the polygon.
an Iterator
that can be used to iterate over the
veritces in the polygon
Removes the vertex at the specified index from the polygon.
the vertex that was removed
Replaces the vertex at the specified index with a different point. This mutator is circular; negative indices and indices greater than the size of the polygon are wrapped appropriately.
the previous vertex at the specified index
Computes a simplified version of this polygon, by trying to eliminate vertices that are within a specified tolerance if the perpendicular distance is measured between them and a hypothetical line between two nearby vertices. The higher the tolerance, the fewer points the resulting polygon will have. The original polygon is not modified.
the simplified polygon
Gets the number of vertices in this polygon.
the number of vertices in this polygon