Class dnx.geom.Polygon2
All Packages Class Hierarchy This Package Previous Next Index
Class dnx.geom.Polygon2
java.lang.Object
|
+----dnx.geom.Point2Set
|
+----dnx.geom.Polygon2
- public class Polygon2
- extends Point2Set
Polygon in 2 dimensions.
This class defines a "pseudo-polygon".
A pseudo-polygon comes in two types: an "almost simple polygon" and
a "multigon".
To figure out what that is, start like this:
A _polyline_ is an ordered set of vertices with line segments connecting
successive vertices.
If an additional line segment is added from the last vertex to the
first, the result is a _polygon_.
If all of the line segments of a polyline or polygon are disjoint
from each other (with the exception of the vertices where successive
line segments meet), the result is a _simple polyline_ or
_simple polygon_.
If zero or more simple polylines are unioned with a simple polygon
such that each polyline has exactly one point in common with the
polygon (a vertex of the polygon and one of the two end vertices
of the polyline) and all polylines are disjoint from each other,
the result is an _almost simple polygon_.
This may seem complicated, but this sort of object is what results
from classifying the regions in a planar graph.
An almost simple polygon can be thought of as a polygon where
possibly some of the vertices and edges are duplicated, according
to the described constraints.
A _multigon_ is like a simple polygon but two vertices are allowed
to overlap other than as part of a polyline, with two restrictions:
1) No interior edges can be created as a result;
2) When two parts of the chain meet at a vertex, they cannot cross.
A multigon can actually have several polygonal regions, and is
what results when the outer boundary of a connected planar graph
is traced. The second condition above ensures that the concept
of clockwise or counterclockwise orientation is well-defined.
@author Ben Wing
-
eqv_points
-
-
Polygon2()
- construct an empty polygon.
-
draw(Graphics2)
-
-
edgeIntersectsAnyExistingEdges(Point2, Point2, int)
- Return true of an edge from P1 to P2 would intersect any
existing edges in the polygon.
-
inside(Point2)
- Return true if P is inside the polygon.
-
invalidateCaches()
-
-
isEndOfPolyline(int)
-
-
orientedCCW()
- Return true if the polygon's vertices are oriented counterclockwise,
false if clockwise.
-
pointsOrientedCCW()
-
-
pointsOrientedCW()
-
-
setOrientedCCW(boolean)
- Set whether the polygon is oriented CCW.
-
sledgehammerCheck()
- Check the internal consistency of the polygon.
-
split(int, int)
- Split the polygon into two by drawing an edge between two
points P1 and P2, identified by their indices.
-
toString()
-
eqv_points
protected IntList eqv_points
Polygon2
public Polygon2()
- construct an empty polygon.
invalidateCaches
protected void invalidateCaches()
- Overrides:
- invalidateCaches in class Point2Set
pointsOrientedCCW
public Enumeration pointsOrientedCCW()
pointsOrientedCW
public Enumeration pointsOrientedCW()
inside
public boolean inside(Point2 p)
- Return true if P is inside the polygon.
orientedCCW
public boolean orientedCCW()
- Return true if the polygon's vertices are oriented counterclockwise,
false if clockwise.
setOrientedCCW
public void setOrientedCCW(boolean is_ccw)
- Set whether the polygon is oriented CCW. Do this only
if you really know what you're doing -- the orientation will be
automatically calculated as necessary if not known.
isEndOfPolyline
public boolean isEndOfPolyline(int p)
split
public Polygon2 split(int p1,
int p2)
- Split the polygon into two by drawing an edge between two
points P1 and P2, identified by their indices.
The existing polygon is modified to become the polygon on one
side (specifically, the left side if the polygon is oriented CCW,
and the right side if oriented CW) of the line from P1 to P2, and
the newly returned polygon is the one on the other side. Both
polygons retain the same orientation (CCW or CW) as the original
one.
NOTE: In general, this split process works even if you're
dealing with non-simple polygons, "inverted polygons" (where
the set orientation is backwards from the orientation you'd
get by inspection, and the area "enclosed" by the polygon
is the unbounded area outside of the polygon), etc.
draw
public void draw(Graphics2 g)
edgeIntersectsAnyExistingEdges
public boolean edgeIntersectsAnyExistingEdges(Point2 p1,
Point2 p2,
int skip_this_one)
- Return true of an edge from P1 to P2 would intersect any
existing edges in the polygon. Possibly skip SKIP_THIS_ONE,
which is the edge from point SKIP_THIS_ONE to nextPoint (SKIP_THIS_ONE)
(useful for checking an existing edge for intersections).
Set SKIP_THIS_ONE to -1 if you're not dealing with an existing edge.
sledgehammerCheck
public void sledgehammerCheck()
- Check the internal consistency of the polygon.
This currently checks:
-- no two points are the same
-- no two edges intersect each other
toString
public String toString()
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index