com.hedgehog.geo.twod.shapes
Class Rectangle2D

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
                              extended by com.hedgehog.geo.twod.shapes.ConvexQuadrilateral2D
                                  extended by com.hedgehog.geo.twod.shapes.Rectangle2D
All Implemented Interfaces:
ModelObject, java.lang.Comparable, java.util.Comparator

public class Rectangle2D
extends ConvexQuadrilateral2D
implements ModelObject

Title: Rectangle2D - models a rectangle.

Description: Models a 2D rectangle having straight edges between the vertices. Note that Rectangle2D is derived from ConvexQuadrilateral2D and as a result does not have to be axis-aligned.

It is worth noting that Rectangle2D is part of the Polygon2D hierarchy and as a result is not particularly efficient when it comes to modelling simple axis-aligned rectangles for operations such as pooint-inside tests and point/line clipping. In such cases use class AxisAlignedBox2D instead.

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
Rectangle2D()
          Default constructor.
Rectangle2D(Point2D p0, Point2D p1, Point2D p2, Point2D p3)
          Constructor.
Rectangle2D(Rectangle2D object)
          Copy constructor.
Rectangle2D(java.util.Vector<Point2D> vertices)
          Constructor.
 
Method Summary
 double angleOfRotation(boolean degrees)
          Returns the angle of rotation from the x-axis vector (1,0) and the local x'-axis.
 StraightLine2D bottomEdge()
          Returns the bottom edge.
 Point2D bottomLeftVertex()
          Returns the (minx,miny) point.
 Point2D bottomRightVertex()
          The bottom right vertex.
 java.util.Vector<Point2D> bottomVertices()
          Returns a vector of the 2 bottom vertices.
 Point2D centre()
          Returns the centre.
 Point2D centreAxisPointBottom()
          Returns the point on the bottom edge that the locally vertical centre-line passes through; ie the mid-point of bottomEdge().
 Point2D centreAxisPointLeft()
          Returns the point on the left-hand edge that the locally horizontal centre-line passes through; ie the mid-point of leftEdge().
 Point2D centreAxisPointRight()
          Returns the point on the right-hand edge that the locally horizontal centre-line passes through; ie the mid-point of rightEdge().
 Point2D centreAxisPointTop()
          Returns the point on the top edge that the locally vertical centre-line passes through; ie the mid-point of topEdge().
 Vector2D centreLineAxis(boolean normalised)
          Returns the vector from the rectangle centre to the centreAxisPointRight() point.
 double height()
          Returns the height.
 boolean isAxisAligned(double tolerance)
          Tests whethr or not this rectangle is axis-aligned; ie both bottom and top edges are horizontal and both left and right edges are vertical.
 boolean isEdgesPerpendicular(double tolerance)
          Method for testing that all 4 edges are perpendicular, thus defining a valid rectangle.
 boolean isSquare(double tolerance)
          Tests whether or not this rectangle is a square.
 boolean isValid(double tolerance)
          Tests whether or not this rectangle is valid.
 StraightLine2D leftEdge()
          Returns the left edge.
 java.util.Vector<Point2D> leftVertices()
          The 2 left-hand-side vertices.
 StraightLine2D rightEdge()
          Returns the right ege.
 java.util.Vector<Point2D> rightVertices()
          The 2 right-hand-side vertices.
 StraightLine2D topEdge()
          Returns the top edge.
 Point2D topLeftVertex()
          The top left vertex.
 Point2D topRightVertex()
          The top right vertex.
 java.util.Vector<Point2D> topVertices()
          Returns a vector of the 2 top vertices.
 double width()
          Returns the width.
 
Methods inherited from class com.hedgehog.geo.twod.shapes.ConvexQuadrilateral2D
bimediane0e2, bimediane1e3, diagonalLengths, diagonalv0v1, diagonalv1v3, isParallelogram, isTrapezium, perpendicularDiagonals, polygonType, semiPerimeter
 
Methods inherited from class com.hedgehog.geo.twod.shapes.ConvexStraightEdgePolygon2D
centroidEdgeConeTriangle, centroidEdgeConeTriangle, centroidEdgeConeTriangles, centroidEdgeConeTriangles, centroidEdgeTriangle, centroidEdgeTriangles, exteriorVertexAngle, interiorVertexAngle, isAllInteriorAnglesSame, isEquilateralTriangle, isRegular, pointInCentroidEdgeConeTriangle, pointInCentroidEdgeTriangle, pointInside, pointInside, pointTangents, pointTangents, sumExteriorVertexAngles, sumInteriorVertexAngles
 
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, 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

Rectangle2D

public Rectangle2D()
Default constructor. Allocates a vector of 4 elements, with all vertices equal to (0,0).


Rectangle2D

public Rectangle2D(java.util.Vector<Point2D> vertices)
            throws java.lang.IllegalArgumentException
Constructor. Assigns the specified vector of vertices to this polygon. The vertices must form a valid rectangle but can be arbirarily ordered and do not require that v0 is the bottom left vertex.

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

Rectangle2D

public Rectangle2D(Point2D p0,
                   Point2D p1,
                   Point2D p2,
                   Point2D p3)
Constructor. Constructs a rectangle 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. The vertices must form a vlid rectnagle but can arbirarily ordered and do not require that v0 is the bottom left vertex.

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

Rectangle2D

public Rectangle2D(Rectangle2D object)
Copy constructor.

Parameters:
object - Object to copy.
Method Detail

bottomLeftVertex

public Point2D bottomLeftVertex()
Returns the (minx,miny) point.

Returns:
The bottom left point.

bottomRightVertex

public Point2D bottomRightVertex()
The bottom right vertex.

Returns:
The bottom right vertex.

topLeftVertex

public Point2D topLeftVertex()
The top left vertex.

Returns:
The top left vertex.

topRightVertex

public Point2D topRightVertex()
The top right vertex.

Returns:
The top right vertex.

bottomVertices

public java.util.Vector<Point2D> bottomVertices()
Returns a vector of the 2 bottom vertices.

Returns:
The 2 bottom vertices.

topVertices

public java.util.Vector<Point2D> topVertices()
Returns a vector of the 2 top vertices.

Returns:
The 2 top vertices.

leftVertices

public java.util.Vector<Point2D> leftVertices()
The 2 left-hand-side vertices.

Returns:
The 2 left-hand-side vertices.

rightVertices

public java.util.Vector<Point2D> rightVertices()
The 2 right-hand-side vertices.

Returns:
The 2 right-hand-side vertices.

bottomEdge

public StraightLine2D bottomEdge()
Returns the bottom edge.

Returns:
The bottom edge.

rightEdge

public StraightLine2D rightEdge()
Returns the right ege.

Returns:
The right edge.

topEdge

public StraightLine2D topEdge()
Returns the top edge.

Returns:
The top edgde.

leftEdge

public StraightLine2D leftEdge()
Returns the left edge.

Returns:
The left edge.

centreAxisPointRight

public Point2D centreAxisPointRight()
Returns the point on the right-hand edge that the locally horizontal centre-line passes through; ie the mid-point of rightEdge().

Returns:
The right-hand centre line point.

centreAxisPointLeft

public Point2D centreAxisPointLeft()
Returns the point on the left-hand edge that the locally horizontal centre-line passes through; ie the mid-point of leftEdge().

Returns:
The left-hand centre line point.

centreAxisPointBottom

public Point2D centreAxisPointBottom()
Returns the point on the bottom edge that the locally vertical centre-line passes through; ie the mid-point of bottomEdge().

Returns:
The bottom centre line point.

centreAxisPointTop

public Point2D centreAxisPointTop()
Returns the point on the top edge that the locally vertical centre-line passes through; ie the mid-point of topEdge().

Returns:
The top centre line point.

centreLineAxis

public Vector2D centreLineAxis(boolean normalised)
Returns the vector from the rectangle centre to the centreAxisPointRight() point. This vector defines a local x'-axis. Note that as a rectangle rotates, say, anticlockwise then the right-hand edge becomes the top edge when the angle of rotation is equal to 90 degrees. As a result the bottom edge is now the right-hand edge and the centre line axis calculated based on this new right hand edge. Thus, do not assume that this method can be used to model the centre line axis as it rotates through a complete angular rotation of 360 degrees.

Parameters:
normalised - Indicates whether or not the returned vector is to be normalised.
Returns:
The local x'-axis vector.

angleOfRotation

public double angleOfRotation(boolean degrees)
Returns the angle of rotation from the x-axis vector (1,0) and the local x'-axis. Note that as a rectangle rotates, say, anticlockwise then the right-hand edge becomes the top edge when the angle of rotation is equal to 90 degrees. As a result the bottom edge is now the right-hand edge and the centre line axis calculated based on this new right hand edge. Thus, do not assume that this method can be used to model the centre line axis as it rotates through a complete angular rotation of 360 degrees.

Parameters:
degrees - Specifies whetheror not the returned angle is in degrees or radians.
Returns:
The angle between tis rectangle's local x'axis and the axis vector (1,0).

isSquare

public boolean isSquare(double tolerance)
Tests whether or not this rectangle is a square.

Parameters:
tolerance - Required tolerance.
Returns:
Logical-true if this rectangle is a square.

width

public double width()
Returns the width.

Returns:
Rectangle width.

height

public double height()
Returns the height.

Returns:
Rectangle height.

centre

public Point2D centre()
Returns the centre.

Returns:
Rectangle centre point.

isValid

public boolean isValid(double tolerance)
Tests whether or not this rectangle is valid.

Overrides:
isValid in class Polygon2D
Parameters:
tolerance - Required tolerance.
Returns:
Logical-true if valid, else logical-false.

isEdgesPerpendicular

public boolean isEdgesPerpendicular(double tolerance)
Method for testing that all 4 edges are perpendicular, thus defining a valid rectangle.

Parameters:
tolerance - Required tolerance.
Returns:
Logical-true if this rectangle has perpendidcular edges, else logical-false.

isAxisAligned

public boolean isAxisAligned(double tolerance)
Tests whethr or not this rectangle is axis-aligned; ie both bottom and top edges are horizontal and both left and right edges are vertical.

Parameters:
tolerance - Required tolerance.
Returns:
Logical-true if this rectangle is axis-aligned, else logical-false.