public class Polygon2d extends java.lang.Object implements Renderable, java.lang.Iterable<Vertex2d>
TRANSPARENT, TWO_DIMENSIONAL
Constructor and Description |
---|
Polygon2d() |
Polygon2d(java.util.Collection<? extends Point2d> pnts) |
Polygon2d(java.util.Collection<? extends Point3d> pnts,
RigidTransform3d TPW) |
Polygon2d(double[] coords) |
Polygon2d(Point2d[] pnts) |
Modifier and Type | Method and Description |
---|---|
Vertex2d |
addVertex(double x,
double y) |
void |
appendVertex(Vertex2d vtx) |
void |
clear() |
double |
computeArea() |
double |
computeAreaIntegrals(Vector2d moa1,
Vector3d moa2)
Computes the area integrals of this polygon.
|
double |
computeLength() |
RenderProps |
createRenderProps()
Factory method to create render properties appropriate to this object.
|
boolean |
epsilonEquals(Polygon2d poly,
double eps)
Returns true if this polygon is equal to another polygon within a
prescribed tolerance eps.
|
boolean |
equals(Polygon2d poly)
Returns true if this polygon is equal to another polygon.
|
void |
getBounds(Point2d minValues,
Point2d maxValues) |
void |
getCentroid(Point2d pnt) |
Vertex2d |
getFirstVertex() |
Vertex2d |
getLastVertex() |
double |
getMaxCoordinate() |
Point2d[] |
getPoints() |
int |
getRenderHints()
Returns a bit code giving rendering hints about this renderable.
|
RenderProps |
getRenderProps()
Returns the render properities for this object.
|
void |
getSelection(java.util.LinkedList<java.lang.Object> list,
int qid)
Append to
list the component (or components) associated with
the qid -th selection query issued by this component's render
method. |
java.util.ListIterator |
getVertices() |
Point2d |
intersectRay(Point2d p,
Vector2d u)
Intersects this polygon with a ray defined by p + s u, using O(n) search
of all edges.
|
void |
inverseTransform(AffineTransform2dBase X)
Applies an inverse affine transformation to the vertices of this polygon.
|
boolean |
isConsistent() |
boolean |
isConvex()
Returns
true if this 2d polygon is convex. |
boolean |
isConvex(double angTol)
Returns
true if this 2d polygon is convex, within a presribed
angular tolerance. |
boolean |
isEmpty() |
boolean |
isSelectable()
Returns true if this object is in fact selectable.
|
java.util.Iterator<Vertex2d> |
iterator() |
Vertex2d |
nearestEdge(Point2d nearPnt,
Point2d pnt)
Finds a nearest edge of this polygon to a given point, using a simple
O(n) search of all edges.
|
int |
numSelectionQueriesNeeded()
If this selectable manages its own selection (by issuing selection
queries within its
render method), then this method should
return the maximum number of selection queries that will be
required. |
int |
numVertices() |
void |
prependVertex(Vertex2d vtx) |
void |
prerender(RenderList list)
Called prior to rendering to allow this object to update the internal
state required for rendering (such as by caching rendering coordinates).
|
void |
render(Renderer renderer,
int flags)
Render this object using the functionality of the supplied
Renderer . |
void |
render(Renderer renderer,
RenderProps props,
int flags) |
void |
scan(ReaderTokenizer rtok) |
void |
set(java.util.Collection<? extends Point2d> pnts) |
void |
set(java.util.Collection<? extends Point3d> pnts,
RigidTransform3d TPW) |
void |
set(double[] coords,
int numVertices) |
void |
set(Point2d[] pnts,
int numVertices) |
void |
set(Polygon2d poly) |
void |
setRenderProps(RenderProps props)
Assigns a new set of render properties to this object.
|
void |
shiftFirstVertex() |
void |
shiftVertices(int n) |
ConvexPolygon2d |
simpleConvexHull()
Computes the convex hull of this Polygon2d, under the assumption that it
describes a simple polygon.
|
static ConvexPolygon2d |
simpleConvexHull(java.util.Collection<Point2d> pnts)
Computes the convex hull of a list of points, under the assumption that
they describe a simple polygon.
|
java.lang.String |
toString() |
java.lang.String |
toString(NumberFormat fmt) |
java.lang.String |
toString(java.lang.String fmtStr) |
void |
transform(AffineTransform2dBase X)
Applies a affine transformation to the vertices of this polygon.
|
void |
updateBounds(Point2d minValues,
Point2d maxValues) |
void |
updateBounds(Vector3d pmin,
Vector3d pmax)
Update the minimum and maximum points for this object.
|
public Polygon2d()
public Polygon2d(double[] coords)
public Polygon2d(Point2d[] pnts)
public Polygon2d(java.util.Collection<? extends Point2d> pnts)
public Polygon2d(java.util.Collection<? extends Point3d> pnts, RigidTransform3d TPW)
public java.util.ListIterator getVertices()
public java.util.Iterator<Vertex2d> iterator()
iterator
in interface java.lang.Iterable<Vertex2d>
public Point2d[] getPoints()
public Vertex2d nearestEdge(Point2d nearPnt, Point2d pnt)
pnt
is outside it.nearPnt
- if non-null, returns the point nearest to pnt
pnt
- point for which the nearest distance is soughtpublic Point2d intersectRay(Point2d p, Vector2d u)
p
- starting point of the rayu
- direction of the raypublic int numVertices()
public double getMaxCoordinate()
public Vertex2d addVertex(double x, double y)
public void appendVertex(Vertex2d vtx)
public void prependVertex(Vertex2d vtx)
public boolean isEmpty()
public Vertex2d getLastVertex()
public Vertex2d getFirstVertex()
public void clear()
public void shiftFirstVertex()
public void getCentroid(Point2d pnt)
public double computeLength()
public double computeArea()
public double computeAreaIntegrals(Vector2d moa1, Vector3d moa2)
The polygon can be ordered either clockwise or counter-clockwise.
moa1
- if non-null, returns the first moment of areamoa2
- if non-null, returns the second moment of area (in x and y),
and the product of area (in z)lpublic void set(Polygon2d poly)
public void set(double[] coords, int numVertices)
public void set(Point2d[] pnts, int numVertices)
public void set(java.util.Collection<? extends Point2d> pnts)
public void set(java.util.Collection<? extends Point3d> pnts, RigidTransform3d TPW)
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(java.lang.String fmtStr)
public java.lang.String toString(NumberFormat fmt)
public void scan(ReaderTokenizer rtok) throws java.io.IOException
java.io.IOException
public boolean epsilonEquals(Polygon2d poly, double eps)
poly
- polygon to be compared witheps
- tolerance valueepsilonEquals(maspack.geometry.Polygon2d, double)
public boolean equals(Polygon2d poly)
poly
- polygon to be compared withepsilonEquals(maspack.geometry.Polygon2d, double)
public void shiftVertices(int n)
public boolean isConsistent()
public void transform(AffineTransform2dBase X)
X
- affine transformationpublic void inverseTransform(AffineTransform2dBase X)
X
- affine transformationpublic void prerender(RenderList list)
IsRenderable
list.addIfVisible (obj);
for each of the objects in question.prerender
in interface IsRenderable
list
- list of objects to be renderedpublic void updateBounds(Vector3d pmin, Vector3d pmax)
IsRenderable
updateBounds
in interface IsRenderable
pmin
- minimum pointpmax
- maximum pointpublic void render(Renderer renderer, int flags)
IsRenderable
Renderer
.render
in interface IsRenderable
renderer
- provides the functionality used to perform the rendering.flags
- flags that may be used to control different
aspects of the rendering. Flags are defined in Renderer
and currently include
Renderer.HIGHLIGHT
and
Renderer.SORT_FACES
.public void render(Renderer renderer, RenderProps props, int flags)
public int getRenderHints()
IsRenderable
TRANSPARENT
and
TWO_DIMENSIONAL
.getRenderHints
in interface IsRenderable
public RenderProps createRenderProps()
HasRenderProps
createRenderProps
in interface HasRenderProps
public void setRenderProps(RenderProps props)
HasRenderProps
null
will remove render properties from this object.setRenderProps
in interface HasRenderProps
props
- new render properties for this objectpublic RenderProps getRenderProps()
HasRenderProps
getRenderProps
in interface HasRenderProps
public boolean isSelectable()
IsSelectable
isSelectable
in interface IsSelectable
public int numSelectionQueriesNeeded()
IsSelectable
render
method), then this method should
return the maximum number of selection queries that will be
required. Otherwise, this method should return -1.numSelectionQueriesNeeded
in interface IsSelectable
public void getSelection(java.util.LinkedList<java.lang.Object> list, int qid)
IsSelectable
list
the component (or components) associated with
the qid
-th selection query issued by this component's render
method. This will only be called if this component manages its own
selection (i.e., the number nums
returned by IsSelectable.numSelectionQueriesNeeded()
is positive), and qid
will in
turn be a number between 0 and nums
-1.getSelection
in interface IsSelectable
list
- selected objects are appended to the end of this listqid
- index of the selection querypublic ConvexPolygon2d simpleConvexHull()
The method uses the O(n) time algorithm described by A Melkman, "On-Li Construction of the Convex Hull of a Simple Polyline", Information Processing Letters (1987). The implementation does not use robust predicates and so may produce results that are inaccurate at a machine-precision level.
public static ConvexPolygon2d simpleConvexHull(java.util.Collection<Point2d> pnts)
The method is the same as that used by simpleConvexHull()
.
public boolean isConvex()
true
if this 2d polygon is convex.public boolean isConvex(double angTol)
true
if this 2d polygon is convex, within a presribed
angular tolerance.