|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.hedgehog.HObject
com.hedgehog.geo.GeometricObject
com.hedgehog.geo.twod.GeometricObject2D
com.hedgehog.geo.twod.shapes.Shape2D
com.hedgehog.geo.twod.shapes.Polygon2D
public abstract class Polygon2D
Title: Polygon2D - abstract base class of 2D polygons.
Description: Abstract base class of 2D polygon hierarchy.
Copyright: Copyright (c) Hedgehog Software 2007-2009.
Company: Hedgehog Software.
| Field Summary | |
|---|---|
protected java.util.Vector<Point2D> |
mVertices
Polygon vertices. |
| Fields inherited from class com.hedgehog.HObject |
|---|
mID, mName |
| Constructor Summary | |
|---|---|
Polygon2D()
Default constructor. |
|
Polygon2D(Point2D v0,
Point2D v1,
Point2D v2)
Constructor. |
|
Polygon2D(Point2D v0,
Point2D v1,
Point2D v2,
Point2D v3)
Constructor. |
|
Polygon2D(Polygon2D object)
Copy constructor. |
|
Polygon2D(java.util.Vector<Point2D> vertices)
Constructor. |
|
| Method Summary | |
|---|---|
boolean |
addVertex(Point2D v)
Appends the specified vertex to this polygon's vertex vector. |
boolean |
addVertex(Point2D v,
int index)
Adds/inserts the specified vertex at the specified index. |
boolean |
addVerticesBetween(int prevVertexIndex,
int nextVertexIndex,
java.util.Vector<Point2D> newVertices)
Adds/inserts the specified vector of vertices between prevVertexIndex and nextVertexIndex indices. |
Point2D |
centroid()
Returns the vertex centroid of this polygon. |
void |
clearVertices()
Clears the vertices vector, thus removing all vertices from this polygon. |
int |
edgeIndex(Curve2D e,
boolean bothSenses,
double tolerance)
Returns the Polygon edge index corresponding to an edge else returns -1 if the edge does not belong to the polygon |
java.util.Vector<Curve2D> |
edgesInCommon(Polygon2D p,
boolean bothSenses,
double tolerance)
Returns the edges common to both Polygon objects. |
java.util.Vector<Curve2D> |
edgesNotInCommon(Polygon2D p,
boolean bothSenses,
double tolerance)
Returns the edges that are not common to both Polygon objects. |
Vector2D |
edgeVector(int vertexIndex)
Returns the vector from vertex.index to vertex.index+1. |
abstract Curve2D |
getEdge(int index)
Returns the edge at the specified index. |
java.util.Vector<Curve2D> |
getEdges()
Returns this polygon's edges. |
Point2D |
getVertex(int index)
Returns the vertex at the specified index. |
java.util.Vector<Point2D> |
getVertices()
Returns the verties vector. |
boolean |
isAllEdgesSameLength(double tolerance)
Tests whether or not this polygon's edges are all the same length, within the specified tolerance. |
boolean |
isEdge(Curve2D e,
boolean bothSenses,
double tolerance)
Tests whether or not the specified edge is an edge of the polygon. |
boolean |
isEdgeIndex(int edgeIndex)
Tests whether or not the specified edge index is valid; ie [0:N-1]. |
boolean |
isPentagon()
Tests whether or not this polygon is a pentagon ; ie it has 5 vertices. |
boolean |
isQuadrilateral()
Tests whether or not this polygon is a quadrilateral ; ie it has 4 vertices. |
boolean |
isTriangle()
Tests whether or not this polygon is a triangle ; ie it has 3 vertices. |
boolean |
isValid(double tolerance)
Tests the validity of this polygon. |
boolean |
isVertex(Point2D vertex,
double tolerance)
Tests if the specified point is a vertex of this polygon. |
boolean |
isVertexIndex(int vertexIndex)
Tests whether or not the specified index is a local index of this polygon; ie vertexIndex < 0 || vertexIndex > mVertices.size()-1. |
int |
leftEdgeIndex(Curve2D e)
Returns the 'left' (i.e. |
int |
leftVertexIndex(int vertexIndex)
Returns the 'left' (ie the one before) vertex index before the specified vertex index. |
int |
leftVertexIndex(Point2D v,
double tolerance)
Returns the 'left' (ie the one before) vertex index before a specified vertex. |
Curve2D |
longestEdge()
Returns the longest edge. |
double |
maxVertexXCoordinate()
Returns the maximum x coordinate of this polygon's vertices. |
double |
maxVertexYCoordinate()
Returns the maximum y coordinate of this polygon's vertices. |
Point2D |
maxXVertex()
Returns the vertex having the maximum x coordinate. |
int |
maxXVertexIndex()
Returns the mVertices vector index of the vertex having the maximum x coordinate. |
Point2D |
maxYVertex()
Returns the vertex having the maximum y coordinate. |
int |
maxYVertexIndex()
Returns the mVertices vector index of the vertex having the maximum y coordinate. |
void |
minmax(HDouble xmin,
HDouble xmax,
HDouble ymin,
HDouble ymax)
Returns the min and max (x,y,z) values of this polygon. |
double |
minVertexXCoordinate()
Returns the minimum x coordinate of this polygon's vertices. |
double |
minVertexYCoordinate()
Returns the minimum y coordinate of this polygon's vertices. |
Point2D |
minXVertex()
Returns the vertex having the minimum x coordinate. |
int |
minXVertexIndex()
Returns the mVertices vector index of the vertex having the minimum x coordinate. |
Point2D |
minYVertex()
Returns the vertex having the minimum y coordinate. |
int |
minYVertexIndex()
Returns the mVertices vector index of the vertex having the minimum y coordinate. |
Point2D |
nextVertex(int vIndex)
Returns the vertex after the specified vertex index the ordering of the polygon vertices. |
Point2D |
nextVertex(Point2D v,
double tolerance)
Returns the vertex after the specified vertex wrt the ordering of the polygon vertices. |
int |
nextVertexIndex(int vIndex)
Returns the next vertex index in the inherent order of the vertices in mVertices. |
int |
numberEdges()
Returns the number of edges, which is assumed to be the same as the number of vertices. |
int |
numberVertices()
Returns the number of vertices. |
java.util.Vector<Point2D> |
otherVertices(Point2D v,
double tolerance)
Returns the vector of polygon vertices not containing the specified vertex. |
FloatingPointVector |
parametricValuesOfVertices(Point2D vertex,
boolean sameSense,
double tolerance)
Returns the positions of the vertices from a specified vertex, normalized w.r.t the total polygon perimeter. |
double |
perimeterFromVertexGivenPoint(Point2D vertex,
Point2D p,
boolean sameSense,
double tolerance)
Returns the perimeter of a polygon from a specified vertex upto the point p. |
Point2D |
pointFromVertexGivenPerimeter(Point2D vertex,
double s,
boolean sameSense,
double tolerance)
Returns a point on the boundary of a polygon which is a specified distance from a vertex measured along the polygon boundary. |
boolean |
pointOnBoundary(Point2D p,
double tolerance)
Tests whether or not the specified point lies on the boundary edges of this polygon. |
int |
pointOnEdge(Point2D p,
double tolerance)
Tests if the specified point lies on an edge of the polygon to the specified tolerance. |
Point2D |
previousVertex(int vIndex)
Returns the vertex before the specified vertex index the ordering of the polygon vertices. |
Point2D |
previousVertex(Point2D v,
double tolerance)
Returns the vertex before the specified vertex wrt the ordering of the polygon vertices. |
int |
previousVertexIndex(int vIndex)
Returns the previous vertex index in the inherent order of the vertices in mVertices. |
boolean |
removeVertex(int vertexIndex)
Removes the veretx at the specified index. |
boolean |
removeVertex(int vIndex,
int lIndex,
int rIndex)
Removes a vertex from a polygon with specified left and right vertex indices. |
boolean |
removeVertex(Point2D v,
double tolerance)
Removes a vertex from this Polygon object. |
boolean |
removeVertex(Point2D v,
Point2D left,
Point2D right)
Removes a vertex from a polygon with specified left and right vertices. |
boolean |
replaceVertex(int vertexIndex,
Point2D newVertex)
Replaces the vertex at the specified index with the new vertex. |
boolean |
replaceVertex(Point2D vertex,
Point2D newVertex,
double tolerance)
Replaces the specified vertex with the new vertex. |
boolean |
replaceVerticesBetween(int vi,
int vj,
ForwardBackwardDirection sense,
Point2D newVertex)
Replaces all vertices between vi and vj with the specified vertex. |
boolean |
replaceVerticesBetween(int vi,
int vj,
ForwardBackwardDirection sense,
java.util.Vector<Point2D> newVertices)
Replaces all vertices between vi and vj with the specified vector of vertices. |
int |
rightEdgeIndex(Curve2D e)
Returns the 'right' (i.e. |
int |
rightVertexIndex(int vertexIndex)
Returns the 'right' (ie the one after) vertex index before the specified vertex index. |
int |
rightVertexIndex(Point2D v,
double tolerance)
Returns the 'right' (i.e. |
boolean |
samePolygon(Polygon2D polygon,
boolean sameSequence,
double tolerance)
Tests whether or not the specified polygon is the same as this point set. |
boolean |
setVertex(Point2D vertex,
int index)
Sets the vertex at the specified index to the specified point. |
void |
setVertices(java.util.Vector<Point2D> vertices)
Sets the polygon vertices vector. |
boolean |
shareVertex(Polygon2D p,
double tolerance)
Tests whether or not the specified polygon shares a vertex with this polygon. |
Curve2D |
shortestEdge()
Returns the shortest edge. |
Point2DSet |
toPoint2DSet()
Returns a Point2DSet object of this polygon's vertices. |
java.lang.String |
toString()
Returns a String representation of a Polygon2D object. |
int[] |
vertexIDs()
Returns an array of this polygon's vertex IDs. |
int |
vertexIndex(Point2D vertex,
double tolerance)
Returns the index of the specified vertex. |
ForwardBackwardDirection |
vertexSense(TripleInteger vertexIndices)
Returns the sense (wrt this polygon's inherent vertex ordering) of the specified vertex indices. |
Vector2D |
vertexVector(int vertexIndex)
Returns the Vector2D equivalent of the specified vertex, with the global origin assumed to be (0,0). |
double[] |
verticesArray()
Returns a pointer to an array of this polygon's vertices; required by some rendering software. |
java.util.Vector<Point2D> |
verticesInCommon(Polygon2D p,
double tolerance)
Returns the vertices that are common to both Polygon objects. |
java.util.Vector<Point2D> |
verticesNotInCommon(Polygon2D p,
double tolerance)
Returns the vertices that are not common to both Polygon objects. |
| Methods inherited from class com.hedgehog.geo.twod.shapes.Shape2D |
|---|
area, areaDifference, boundingBox, is2D, is3D, isCurve, isGrid, isMesh, isPoint, isPointSet, isShape, isSurface, perimeter, pointInside, pointOutside, rotate, scale, translate, translate |
| Methods inherited from class com.hedgehog.geo.GeometricObject |
|---|
objectDimension |
| Methods inherited from class com.hedgehog.HObject |
|---|
clone, compare, compareTo, copy, equals, getID, getName, hashCode, hasID, hasName, setID, setName |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.hedgehog.model.ModelObject |
|---|
childModelObjects, databaseInsertStatement, databaseUpdateStatement, fromDatabase, fromXMLNode, toX3DNode, toXMLNode |
| Field Detail |
|---|
protected java.util.Vector<Point2D> mVertices
| Constructor Detail |
|---|
public Polygon2D()
public Polygon2D(java.util.Vector<Point2D> vertices)
throws java.lang.IllegalArgumentException
vertices - Vector polygon vertices.
java.lang.IllegalArgumentException - Thrown if argument vertices does not have at least 3 elements.
public Polygon2D(Point2D v0,
Point2D v1,
Point2D v2)
v0 - Vertex 0.v1 - Vertex 1.v2 - Vertex 2.
public Polygon2D(Point2D v0,
Point2D v1,
Point2D v2,
Point2D v3)
v0 - Vertex 0.v1 - Vertex 1.v2 - Vertex 2.v3 - Vertex 3.public Polygon2D(Polygon2D object)
object - Object to copy.| Method Detail |
|---|
public java.util.Vector<Point2D> getVertices()
public void setVertices(java.util.Vector<Point2D> vertices)
vertices - New polygon verties vector.
public Point2D getVertex(int index)
throws java.lang.IllegalArgumentException
index - Vertex index.
java.lang.IllegalArgumentException - Thrown if index is invalid.
public boolean setVertex(Point2D vertex,
int index)
throws java.lang.IllegalArgumentException
vertex - Point.index - Index.
java.lang.IllegalArgumentException - Thrown if index is invalid.
public boolean samePolygon(Polygon2D polygon,
boolean sameSequence,
double tolerance)
polygon - Polygon to compare.sameSequence - Specifies whether or not an exact match is performed on the vertex sets of both polygons.tolerance - Required tolerance.
public boolean shareVertex(Polygon2D p,
double tolerance)
p - Polygon to compare against this polygon.tolerance - Required tolerance.
public int numberEdges()
public int numberVertices()
public boolean isValid(double tolerance)
tolerance - Required tolerance.
public boolean isVertex(Point2D vertex,
double tolerance)
vertex - Point to test.tolerance - Required tolerance.
public boolean isVertexIndex(int vertexIndex)
vertexIndex - Vertex index to test.
public boolean isEdge(Curve2D e,
boolean bothSenses,
double tolerance)
e - Edge to test.bothSenses - If true then both sense of (p0-p1) and (p1-p0) are matched, else just the (p0-p1) sense.tolerance - Required tolerance.
public boolean isAllEdgesSameLength(double tolerance)
tolerance - Required tolerance.
public boolean isTriangle()
public boolean isQuadrilateral()
public boolean isPentagon()
public boolean isEdgeIndex(int edgeIndex)
edgeIndex - Edge index to test.
public int vertexIndex(Point2D vertex,
double tolerance)
vertex - Polygon vertex.tolerance - Required tolerance.
public Vector2D vertexVector(int vertexIndex)
throws java.lang.IllegalArgumentException
vertexIndex - Vertex index of vertices.
java.lang.IllegalArgumentException - Thrown if vertexIndex is out of range [0:N-1].public int[] vertexIDs()
public double[] verticesArray()
public ForwardBackwardDirection vertexSense(TripleInteger vertexIndices)
throws java.lang.IllegalArgumentException
vertexIndices - Vertex indices.
java.lang.IllegalArgumentException - Thrown if any of the values of vertexIndices are invalid vertex indices.public boolean addVertex(Point2D v)
v - Vertex to add.
public boolean addVertex(Point2D v,
int index)
v - Vertex to add.index - Index in this polygon's points vector.
public boolean addVerticesBetween(int prevVertexIndex,
int nextVertexIndex,
java.util.Vector<Point2D> newVertices)
throws java.lang.IllegalArgumentException
prevVertexIndex - Previous vertex index.nextVertexIndex - Next vertex index.newVertices - Vector of new vertices to insert between prevVertexIndex and nextVertexIndex.
java.lang.IllegalArgumentException - Thrown if prevVertexIndex or nextVertexIndex are invalid indices or newVertices is null or empty.public void clearVertices()
public boolean removeVertex(Point2D v,
double tolerance)
throws java.lang.IllegalArgumentException
v - Vertex to delete.tolerance - Required tolerance.
java.lang.IllegalArgumentException - Thrown if v is not a vertex of this polygon.public boolean removeVertex(int vertexIndex)
vertexIndex - Index of vertex to remove.
public boolean removeVertex(Point2D v,
Point2D left,
Point2D right)
v - Vertex to remove.left - Left vertex.right - Right vertex.
public boolean removeVertex(int vIndex,
int lIndex,
int rIndex)
vIndex - Vertex index to remove.lIndex - Left vertex index to remove.rIndex - Right vertex index to remove.
public Point2D nextVertex(Point2D v,
double tolerance)
v - Vertex of polygon.tolerance - Required tolerance.
public Point2D nextVertex(int vIndex)
throws java.lang.IllegalArgumentException
vIndex - Vertex index.
java.lang.IllegalArgumentException - Thrown if vIndex is out of range.
public int nextVertexIndex(int vIndex)
throws java.lang.IllegalArgumentException
vIndex - Vertex index.
java.lang.IllegalArgumentException - Thrown if vIndex is out of range.
public boolean replaceVertex(int vertexIndex,
Point2D newVertex)
vertexIndex - Veretx index to replace.newVertex - New vertex.
public boolean replaceVertex(Point2D vertex,
Point2D newVertex,
double tolerance)
vertex - Vertex to replace.newVertex - New vertex.tolerance - Required tolerance.
public boolean replaceVerticesBetween(int vi,
int vj,
ForwardBackwardDirection sense,
java.util.Vector<Point2D> newVertices)
throws java.lang.IllegalArgumentException
vi - Vertex index.vj - Vertex index.sense - Sense (forward/backward) between vi and vj.newVertices - Vector of new vertices to insert between vi nad vj.
java.lang.IllegalArgumentException - Thrown if vi or vj are invalid indices, newVertices is null or empty or sense is null or equal to STATIONARY.
public boolean replaceVerticesBetween(int vi,
int vj,
ForwardBackwardDirection sense,
Point2D newVertex)
throws java.lang.IllegalArgumentException
vi - Vertex index.vj - Vertex index.sense - Sense (forward/backward) between vi and vjnewVertex - New vertex.
java.lang.IllegalArgumentException - Thrown if vi or vj are invalid indices, newVertex is null or sense is null or equal to STATIONARY..
public Point2D previousVertex(Point2D v,
double tolerance)
v - Vertex of polygon.tolerance - Required tolerance.
public Point2D previousVertex(int vIndex)
throws java.lang.IllegalArgumentException
vIndex - Vertex index.
java.lang.IllegalArgumentException - Thrown if vIndex is out of range.
public int previousVertexIndex(int vIndex)
throws java.lang.IllegalArgumentException
vIndex - Vertex index.
java.lang.IllegalArgumentException - Thrown if vIndex is out of range.
public int pointOnEdge(Point2D p,
double tolerance)
p - Point to test.tolerance - Required tolerance.
public boolean pointOnBoundary(Point2D p,
double tolerance)
pointOnBoundary in class Shape2Dp - Point to test.tolerance - Required tolerance.
public java.util.Vector<Point2D> otherVertices(Point2D v,
double tolerance)
throws java.lang.IllegalArgumentException
v - Polygon vertex.tolerance - Required tolerance.
java.lang.IllegalArgumentException - Thrown if v is null is not a vertex of this polygon.
public java.util.Vector<Curve2D> edgesInCommon(Polygon2D p,
boolean bothSenses,
double tolerance)
throws java.lang.IllegalArgumentException
p - Polygon to compare.bothSenses - If true then both edge sense are compared, else just the inherent sense of the polygon edges.tolerance - Required tolerance.
java.lang.IllegalArgumentException - Thrown if p is null.
public java.util.Vector<Curve2D> edgesNotInCommon(Polygon2D p,
boolean bothSenses,
double tolerance)
throws java.lang.IllegalArgumentException
p - Polygon to compare.bothSenses - If true then both edge sense are compared, else just the inherent sense of the polygon edges.tolerance - Required tolerance.
java.lang.IllegalArgumentException - Thrown if p is null.
public java.util.Vector<Point2D> verticesInCommon(Polygon2D p,
double tolerance)
throws java.lang.IllegalArgumentException
p - Polygon to compare against this polygon for common vertices.tolerance - Required tolerance used by samePoint().
java.lang.IllegalArgumentException - Thrown if p is null.
public java.util.Vector<Point2D> verticesNotInCommon(Polygon2D p,
double tolerance)
throws java.lang.IllegalArgumentException
p - Polygon to compare against this polygon for non-common vertices.tolerance - Require tolerance.
java.lang.IllegalArgumentException - Thrown if p is null.
public Vector2D edgeVector(int vertexIndex)
throws java.lang.IllegalArgumentException
vertexIndex - Start index of vertices.
java.lang.IllegalArgumentException - Thrown if vertexIndex is out of range [0:N-1].
public int edgeIndex(Curve2D e,
boolean bothSenses,
double tolerance)
e - Edge.bothSenses - Specifies whether or not both senses of the curve are examined to find a match.tolerance - Required tolerance.
public Point2D maxXVertex()
public int maxXVertexIndex()
public Point2D maxYVertex()
public int maxYVertexIndex()
public Point2D minXVertex()
public int minXVertexIndex()
public Point2D minYVertex()
public int minYVertexIndex()
public double maxVertexXCoordinate()
public double maxVertexYCoordinate()
public double minVertexXCoordinate()
public double minVertexYCoordinate()
public void minmax(HDouble xmin,
HDouble xmax,
HDouble ymin,
HDouble ymax)
xmin - Set upon return to the minimum x coordinate of polygon.ymin - Set upon return to the minimum y coordinate of polygon.xmax - Set upon return to the maximum x coordinate of polygon.ymax - Set upon return to the maximum y coordinate of polygon.public int leftVertexIndex(int vertexIndex)
vertexIndex - Vertex index.
public int rightVertexIndex(int vertexIndex)
vertexIndex - Vertex index.
public int leftVertexIndex(Point2D v,
double tolerance)
v - Vertex to find left vertex of.tolerance - Required tolerance.
public int rightVertexIndex(Point2D v,
double tolerance)
v - Vertex to find right vertex of.tolerance - Required tolerance.
public int leftEdgeIndex(Curve2D e)
e - Curve to find the left index of.
public int rightEdgeIndex(Curve2D e)
e - Curve to find the right index of.
public Curve2D longestEdge()
throws InvalidObjectException
InvalidObjectException - Thrown if this polygon has no edges.
public Curve2D shortestEdge()
throws InvalidObjectException
InvalidObjectException - Thrown if this polygon has no edges.public java.util.Vector<Curve2D> getEdges()
public FloatingPointVector parametricValuesOfVertices(Point2D vertex,
boolean sameSense,
double tolerance)
throws java.lang.IllegalArgumentException
vertex - Source vertex from which to measure positions of other vertices.sameSense - If true then vertices traversed in same order as internal vector, else in opposite direction.tolerance - Required tolerance.
java.lang.IllegalArgumentException - Thrown if vertex is not a vertex of this polygon.
public double perimeterFromVertexGivenPoint(Point2D vertex,
Point2D p,
boolean sameSense,
double tolerance)
throws java.lang.IllegalArgumentException
vertex - Vertex of polygon from which to measure perimeter from.p - Point on polygon boundary up to which perimeter is measured.sameSense - If true then vertices traversed in same order as internal vector, else in opposite direction.tolerance - Required tolerance.
java.lang.IllegalArgumentException - Thrown if vertex is not a vertex of this polygon.
public Point2D pointFromVertexGivenPerimeter(Point2D vertex,
double s,
boolean sameSense,
double tolerance)
throws java.lang.IllegalArgumentException
vertex - Source vertex from which to measure.s - Distance from vertex.sameSense - If true then vertices traversed in same order as internal vector, else in opposite direction.tolerance - Required tolerance.
java.lang.IllegalArgumentException - Thrown if vertex is not a vertex of this polygon or s is either less than zero or greater than the polygon perimeter.public java.lang.String toString()
toString in class java.lang.Objectpublic Point2DSet toPoint2DSet()
public Point2D centroid()
centroid in class Shape2D
public abstract Curve2D getEdge(int index)
throws java.lang.IllegalArgumentException
index - Edge index.
java.lang.IllegalArgumentException - Thrown if index is invalid.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||