com.hedgehog.geo.twod.shapes
Class ConvexStraightEdgePolygon2D

java.lang.Object
  extended by com.hedgehog.HObject
      extended by com.hedgehog.geo.GeometricObject
          extended by com.hedgehog.geo.twod.GeometricObject2D
              extended by com.hedgehog.geo.twod.shapes.Shape2D
                  extended by com.hedgehog.geo.twod.shapes.Polygon2D
                      extended by com.hedgehog.geo.twod.shapes.StraightEdgePolygon2D
                          extended by com.hedgehog.geo.twod.shapes.ConvexStraightEdgePolygon2D
All Implemented Interfaces:
ModelObject, java.lang.Comparable, java.util.Comparator
Direct Known Subclasses:
ConvexQuadrilateral2D, RegularPolygon2D

public class ConvexStraightEdgePolygon2D
extends StraightEdgePolygon2D
implements ModelObject

Title: ConvexStraightEdgePolygon2D - models a convex polygon.

Description: Extends StraightEdgePolygon2D specifically for convex polygons.

Copyright: Copyright (c) Hedgehog Software 2007-2009.

Company: Hedgehog Software..

Since:
1.0
Version:
1.1

Field Summary
 
Fields inherited from class com.hedgehog.geo.twod.shapes.Polygon2D
mVertices
 
Fields inherited from class com.hedgehog.HObject
mID, mName
 
Constructor Summary
ConvexStraightEdgePolygon2D()
          Default constructor.
ConvexStraightEdgePolygon2D(ConvexStraightEdgePolygon2D object)
          Copy constructor.
ConvexStraightEdgePolygon2D(Point2D p0, Point2D p1, Point2D p2)
          Constructor.
ConvexStraightEdgePolygon2D(Point2D p0, Point2D p1, Point2D p2, Point2D p3)
          Constructor.
ConvexStraightEdgePolygon2D(java.util.Vector<Point2D> vertices)
          Constructor.
 
Method Summary
 StraightEdgeTriangle2D centroidEdgeConeTriangle(int edgeIndex)
          Returns the triangle formed by the centroid and the intersection of the lines through the specified edge and this triangle's bounding centroid circle.
 StraightEdgeTriangle2D centroidEdgeConeTriangle(int edgeIndex, double radius)
          Returns the triangle formed by the centroid and the intersection of the lines through the specified edge and a circle of the specified radius centred at this triangle's centroid.
 java.util.Vector<StraightEdgeTriangle2D> centroidEdgeConeTriangles()
          Returns vector of triangles formed by the centroid and the intersection of the lines through all triangle edges and this triangle's centroid focused bounding circle.
 java.util.Vector<StraightEdgeTriangle2D> centroidEdgeConeTriangles(double radius)
          Returns vector of triangles formed by the centroid and the intersection of the lines through all triangle edges and a circle of the specified radius centred at this triangle's centroid.
 StraightEdgeTriangle2D centroidEdgeTriangle(int edgeIndex)
          Returns the triangle formed by the centroid and the two end-points of the specified edge.
 java.util.Vector<StraightEdgeTriangle2D> centroidEdgeTriangles()
          Returns the vector of the 3 centroid focused edge triangles for this triangle.
 double exteriorVertexAngle(int vertexIndex, boolean degrees)
          Returns the exterior angle at the specified vertex.
 double interiorVertexAngle(int vertexIndex, boolean degrees)
          Returns the interior angle at the specified vertex.
 boolean isAllInteriorAnglesSame(double tolerance)
          Tests whether or not all interior angles are the same.
 boolean isEquilateralTriangle(double tolerance)
          Tests whether or not this polygon is an equilateral triangle.
 boolean isRegular(double tolerance)
          Tests whether or not this convex polygon is regular; ie all edges are of the same length and all interior angles are equal.
 PairPQ<StraightEdgeTriangle2D,HInteger> pointInCentroidEdgeConeTriangle(Point2D p, double radius, double tolerance)
          Returns the centroid edge cone triangle that the specified point is inside or on the boundary.
 PairPQ<StraightEdgeTriangle2D,HInteger> pointInCentroidEdgeTriangle(Point2D p, double tolerance)
          Returns the centroid edge triangle that the specified point is inside or on the boundary.
 boolean pointInside(Point2D p, double tolerance)
          Tests whether or not the specified point is inside this polygon.
 boolean pointInside(Point2D p, Point2D centroid, double tolerance)
          Tests whether or not the specified point is inside this polygon.
 java.util.Vector<PairPQ<StraightLine2D,HInteger>> pointTangents(Point2D p, boolean pTestInside, double tolerance)
          Returns the tangents from the specified point to the vertices of this polygon.
 java.util.Vector<PairPQ<StraightLine2D,HInteger>> pointTangents(Point2D p, java.util.Vector<StraightEdgeTriangle2D> centroidEdgeConeTriangles, boolean pTestInside, double tolerance)
          Returns the tangents from the specified point to the vertices of this polygon.
 double sumExteriorVertexAngles(boolean degrees)
          Returns the sum of all the exterior vertex angles of this polygon.
 double sumInteriorVertexAngles(boolean degrees)
          Returns the sum of all the interior vertex angles of this polygon.
 
Methods inherited from class com.hedgehog.geo.twod.shapes.StraightEdgePolygon2D
area, boundingBox, boundingCentroidCircle, childModelObjects, circleInside, convexHull, curveInPolygon, databaseInsertStatement, databaseUpdateStatement, dissectionIntoTriangles, dissectionIntoTriangulation, earVertex, edgesAboveHorizontalLine, edgesBelowHorizontalLine, edgesCutByHorizontalLine, edgesCutByVerticalLine, edgesToLeftOfVerticalLine, edgesToRightOfVerticalLine, fromDatabase, fromXMLNode, getEdge, intersection, isConvex, isConvexVertex, isConvexVertex, isConvexVertex, isDiagonal, isEarVertex, isEquiangular, isSimple, perimeter, pointInsideCrossingNumber, pointInsideWindingNumber, pointOutside, rotate, scale, signedArea, simplifiedPolygon, toIndexPolygon2D, toStraightEdgeTriangle2D, toString, toX3DNode, toXMLNode, translate, vertexIndexAdjacentTriples, vertexOrdering
 
Methods inherited from class com.hedgehog.geo.twod.shapes.Polygon2D
addVertex, addVertex, addVerticesBetween, centroid, clearVertices, edgeIndex, edgesInCommon, edgesNotInCommon, edgeVector, getEdges, getVertex, getVertices, isAllEdgesSameLength, isEdge, isEdgeIndex, isPentagon, isQuadrilateral, isTriangle, isValid, isVertex, isVertexIndex, leftEdgeIndex, leftVertexIndex, leftVertexIndex, longestEdge, maxVertexXCoordinate, maxVertexYCoordinate, maxXVertex, maxXVertexIndex, maxYVertex, maxYVertexIndex, minmax, minVertexXCoordinate, minVertexYCoordinate, minXVertex, minXVertexIndex, minYVertex, minYVertexIndex, nextVertex, nextVertex, nextVertexIndex, numberEdges, numberVertices, otherVertices, parametricValuesOfVertices, perimeterFromVertexGivenPoint, pointFromVertexGivenPerimeter, pointOnBoundary, pointOnEdge, previousVertex, previousVertex, previousVertexIndex, removeVertex, removeVertex, removeVertex, removeVertex, replaceVertex, replaceVertex, replaceVerticesBetween, replaceVerticesBetween, rightEdgeIndex, rightVertexIndex, rightVertexIndex, samePolygon, setVertex, setVertices, shareVertex, shortestEdge, toPoint2DSet, vertexIDs, vertexIndex, vertexSense, vertexVector, verticesArray, verticesInCommon, verticesNotInCommon
 
Methods inherited from class com.hedgehog.geo.twod.shapes.Shape2D
areaDifference, is2D, is3D, isCurve, isGrid, isMesh, isPoint, isPointSet, isShape, isSurface, 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
 

Constructor Detail

ConvexStraightEdgePolygon2D

public ConvexStraightEdgePolygon2D()
Default constructor. Since the minimum valid polygon is a triangle the constructor allocates a vector of 3 elements with all three vertices equal to (0,0).


ConvexStraightEdgePolygon2D

public ConvexStraightEdgePolygon2D(java.util.Vector<Point2D> vertices)
                            throws java.lang.IllegalArgumentException
Constructor. Assigns the specified vector of vertices to this polygon.

Parameters:
vertices - Vector polygon vertices.
Throws:
java.lang.IllegalArgumentException - Thrown if argument vertices does not have at least 3 elements.

ConvexStraightEdgePolygon2D

public ConvexStraightEdgePolygon2D(Point2D p0,
                                   Point2D p1,
                                   Point2D p2)
Constructor. Constructs a triangle from the specified three points. No tests are performed as to whether the points are at the same geometric positions or collinear and non-null and it is thus the responsibility of the method-caller to ensure that a valid quadrilateral is being defined.

Parameters:
p0 - Point 0.
p1 - Point 1.
p2 - Point 2.

ConvexStraightEdgePolygon2D

public ConvexStraightEdgePolygon2D(Point2D p0,
                                   Point2D p1,
                                   Point2D p2,
                                   Point2D p3)
Constructor. Constructs a convex quadrilateral from the specified four points. No tests are performed as to whether the points are at the same geometric positions or collinear and non-null and it is thus the responsibility of the method-caller to ensure that a valid quadrilateral is being defined.

Parameters:
p0 - Point 0.
p1 - Point 1.
p2 - Point 2.
p3 - Point 3.

ConvexStraightEdgePolygon2D

public ConvexStraightEdgePolygon2D(ConvexStraightEdgePolygon2D object)
Copy constructor.

Parameters:
object - Object to copy.
Method Detail

centroidEdgeTriangle

public StraightEdgeTriangle2D centroidEdgeTriangle(int edgeIndex)
                                            throws java.lang.IllegalArgumentException
Returns the triangle formed by the centroid and the two end-points of the specified edge.

Parameters:
edgeIndex - Polygon edge index.
Returns:
Triangle with vertices (centroid,edge.p0,edge.p1).
Throws:
java.lang.IllegalArgumentException - Thrown if edgeIndex is invalid.

centroidEdgeTriangles

public java.util.Vector<StraightEdgeTriangle2D> centroidEdgeTriangles()
Returns the vector of the 3 centroid focused edge triangles for this triangle.

Returns:
Vector of the 3 centroid focused edge triangles for this triangle.

centroidEdgeConeTriangle

public StraightEdgeTriangle2D centroidEdgeConeTriangle(int edgeIndex)
                                                throws java.lang.IllegalArgumentException
Returns the triangle formed by the centroid and the intersection of the lines through the specified edge and this triangle's bounding centroid circle.

Parameters:
edgeIndex - Triangle edge index.
Returns:
The triangle formed by the centroid and the intersection of the lines through the specified edge and this triangle's bounding centroid circle.
Throws:
java.lang.IllegalArgumentException - Thrown if edgeIndex is invalid.

centroidEdgeConeTriangle

public StraightEdgeTriangle2D centroidEdgeConeTriangle(int edgeIndex,
                                                       double radius)
                                                throws java.lang.IllegalArgumentException
Returns the triangle formed by the centroid and the intersection of the lines through the specified edge and a circle of the specified radius centred at this triangle's centroid.

Parameters:
edgeIndex - Triangle edge index.
radius - Circle radius.
Returns:
The triangle formed by the centroid and the intersection of the lines through the specified edge and a circle of the specified radius centred at this triangle's centroid.
Throws:
java.lang.IllegalArgumentException - Thrown if edgeIndex is invalid or radius<=0.

centroidEdgeConeTriangles

public java.util.Vector<StraightEdgeTriangle2D> centroidEdgeConeTriangles()
                                                                   throws java.lang.IllegalArgumentException
Returns vector of triangles formed by the centroid and the intersection of the lines through all triangle edges and this triangle's centroid focused bounding circle.

Returns:
Vector of centroid edge cone triangles.
Throws:
java.lang.IllegalArgumentException - Thrown if this triangle's bounding centroid circle radius is zero.

centroidEdgeConeTriangles

public java.util.Vector<StraightEdgeTriangle2D> centroidEdgeConeTriangles(double radius)
                                                                   throws java.lang.IllegalArgumentException
Returns vector of triangles formed by the centroid and the intersection of the lines through all triangle edges and a circle of the specified radius centred at this triangle's centroid.

Parameters:
radius - Radus of bounding circle focused at this triangle's centroid.
Returns:
Vector of centroid edge cone triangles.
Throws:
java.lang.IllegalArgumentException - Thrown if radius<=0.0.

pointInCentroidEdgeTriangle

public PairPQ<StraightEdgeTriangle2D,HInteger> pointInCentroidEdgeTriangle(Point2D p,
                                                                           double tolerance)
Returns the centroid edge triangle that the specified point is inside or on the boundary.

Parameters:
p - Point to test.
tolerance - Required tolerance.
Returns:
Pair of the edge-centroid-triangle containing p. A null value is returned if p is outside this polygon.

pointInCentroidEdgeConeTriangle

public PairPQ<StraightEdgeTriangle2D,HInteger> pointInCentroidEdgeConeTriangle(Point2D p,
                                                                               double radius,
                                                                               double tolerance)
Returns the centroid edge cone triangle that the specified point is inside or on the boundary.

Parameters:
p - Point to test.
radius - Enclosing outer radius.
tolerance - Required tolerance.
Returns:
Pair of the edge-centroid-coene-triangle containing p. A null value is returned if p is outside this polygon.

pointInside

public boolean pointInside(Point2D p,
                           Point2D centroid,
                           double tolerance)
Tests whether or not the specified point is inside this polygon. Overrides StraightEdgePolygon2D.pointInside() since a more efficient test can be usd for convex polygons. The method used is to test whether the test point is on the same side of an edge as the specified polygon centroid.

Overrides:
pointInside in class StraightEdgePolygon2D
Parameters:
p - Point to test.
centroid - Polygon centroid. In fact any interior point can be used.
tolerance - Required tolerance.
Returns:
Logical-true if p is on the boundary or inside this polygon, else logical-false.

pointInside

public boolean pointInside(Point2D p,
                           double tolerance)
Tests whether or not the specified point is inside this polygon. Overrides StraightEdgePolygon2D.pointInside() since a more efficient test can be usd for convex polygons. The method used is to test whether the test point is on the same side of an edge as the polygon centroid.

Overrides:
pointInside in class StraightEdgePolygon2D
Parameters:
p - Point to test.
tolerance - Required tolerance.
Returns:
Logical-true if p is on the boundary or inside this polygon, else logical-false.

pointTangents

public java.util.Vector<PairPQ<StraightLine2D,HInteger>> pointTangents(Point2D p,
                                                                       boolean pTestInside,
                                                                       double tolerance)
Returns the tangents from the specified point to the vertices of this polygon. Internally constructs the centroid edge cone triangles from the centroid out to a distance of twice the enclosing circle radius.

Parameters:
p - Point from which to generate the tangents.
pTestInside - Specifies whether or not to test if p is inside this polygon. Used for saving a p-inside test if the point is known to be outside.
tolerance - Required tolerance.
Returns:
Point tangents or null if p is inside this polygon, outside the vector of centroid edge cone triangles or an error occurred.

pointTangents

public java.util.Vector<PairPQ<StraightLine2D,HInteger>> pointTangents(Point2D p,
                                                                       java.util.Vector<StraightEdgeTriangle2D> centroidEdgeConeTriangles,
                                                                       boolean pTestInside,
                                                                       double tolerance)
Returns the tangents from the specified point to the vertices of this polygon. The tangents are the two straight lines from the specified point (p) to visible vertices such that all vertices are inside the cone eminating from the apex p. The test is with respect to the vector of this polygon's centroid-edge-cone-triangles, and it is assumed that p falls inside one of these triangles.

Parameters:
p - Point from which to find the tangents.
centroidEdgeConeTriangles - Vector of triangles focused at this polygon's centroid, extending out to a previously specified radius. The ordering of centroidEdgeConeTriangles corresponds to the edge ordering of this polygon.
pTestInside - Specifies whether or not to test if p is inside this polygon. Used for saving a p-inside test if the point is known to be outside.
tolerance - Required tolerance.
Returns:
Point tangents or null if p is inside this polygon, outside the vector of centroid edge cone triangles or an error occurred.

interiorVertexAngle

public double interiorVertexAngle(int vertexIndex,
                                  boolean degrees)
                           throws java.lang.IllegalArgumentException
Returns the interior angle at the specified vertex.

Overrides:
interiorVertexAngle in class StraightEdgePolygon2D
Parameters:
vertexIndex - Vertex index.
degrees - Specifies whether or not the returned angle is in degrees or radians.
Returns:
The interior angle at the specified vertex.
Throws:
java.lang.IllegalArgumentException - Thrown if the specified vertex index is out of range.

exteriorVertexAngle

public double exteriorVertexAngle(int vertexIndex,
                                  boolean degrees)
                           throws java.lang.IllegalArgumentException
Returns the exterior angle at the specified vertex.

Overrides:
exteriorVertexAngle in class StraightEdgePolygon2D
Parameters:
vertexIndex - Vertex index.
degrees - Specifies whether or not the returned angle is in degrees or radians.
Returns:
The exterior angle at the specified vertex.
Throws:
java.lang.IllegalArgumentException - Thrown if the specified vertex index is out of range.

isAllInteriorAnglesSame

public boolean isAllInteriorAnglesSame(double tolerance)
Tests whether or not all interior angles are the same.

Parameters:
tolerance - Required tolerance.
Returns:
Logical-true if all interior angles of this polygon are the same, else logical-false.

sumInteriorVertexAngles

public double sumInteriorVertexAngles(boolean degrees)
Returns the sum of all the interior vertex angles of this polygon.

Parameters:
degrees - Specifies whether or not the returned angle is in degrees or radians.
Returns:
The sum of all the interior vertex angles of this polygon.

sumExteriorVertexAngles

public double sumExteriorVertexAngles(boolean degrees)
Returns the sum of all the exterior vertex angles of this polygon.

Parameters:
degrees - Specifies whether or not the returned angle is in degrees or radians.
Returns:
The sum of all the exterior vertex angles of this polygon.

isRegular

public boolean isRegular(double tolerance)
Tests whether or not this convex polygon is regular; ie all edges are of the same length and all interior angles are equal.

Parameters:
tolerance - Required tolerance.
Returns:
Logical-true if this polygon is regular, else logical-false.

isEquilateralTriangle

public boolean isEquilateralTriangle(double tolerance)
Tests whether or not this polygon is an equilateral triangle.

Parameters:
tolerance - Required tolerance.
Returns:
Logical-true if this polygon is an equilateral triangle, else logical-false.