|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectgizmoball.shape.Polygon
public class Polygon
This class represents a polygon object, implemented as an array of vertices and an array of edges. Polygon implements the Shape interface, and has factory methods used to generate rectangles, squares, and right triangles. Representation Invariant: vertices and edges have same size: vertices.size() = edges.size(), there are at least three vertices: vertices.size() > 2, edges represents line segments of consecutive vertices: for i = 0 to vertices.size()-2 edges.get(i).getv1().equals(vertices.get(i) && edges.get(i).getv2().equals(vertices.get(i+1) edges.get(edges.size()-1).getv1().equals(vertices.get(edges.size()-1) && edges.get(edges.size()-1).getv2().equals(vertices.get(0) line segments do not intersect: for i = 1 to edges.size()-1 for j = i to edges.size() - 1 !ShapeGeometry.lineSegmentsIntersect(edges.get(i), edges.get(j))
| Constructor Summary | |
|---|---|
Polygon(java.util.List<Vect> vertexList)
Constructor for polygon taking a list of vertices as input. |
|
| Method Summary | |
|---|---|
static boolean |
canCreatePoly(java.util.List<Vect> vertexList)
|
boolean |
containsPoint(Vect pt)
Returns true iff the specified point is in the interior of the polygon. |
java.util.List<Circle> |
getCircles()
Returns a list of Circle objects present in polygon, consisting of circles of radius zero for each of the vertices |
java.util.List<LineSegment> |
getLineSegments()
Returns a list of LineSegment objects present in polygon, consisting of edges in polygon |
java.util.List<Vect> |
getVertices()
|
static Polygon |
makeRectangle(Vect upperLeft,
double width,
double height)
makes a rectangle at the specified location with the specified length and width |
static Polygon |
makeRightTriangle45(Vect upperLeft,
double length)
Constructs a 45-45-90 triangle with the right angle in the bottom left |
static Polygon |
makeSquare(Vect upperLeft,
double length)
Returns a polygon that is a square whose upperleft corner is specified by upperLeft and whose side lengths are specified by length |
Vect |
maxXY()
Returns the maximum coordinates for a bounding rectangle of the polygon. |
Vect |
minXY()
Returns the minimum coordinates for a bounding rectangle of the polygon. |
Polygon |
rotate(Angle theta,
Vect centerOfRotation)
Rotates the polygon by an Angle theta around an arbitrary point centerOfRotation and returns the new Polygon object |
Polygon |
translate(Vect v)
Translates the polygon by a Vect v and returns the new polygon object |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Polygon(java.util.List<Vect> vertexList)
vertexList - list of Vect objects representing vertices of polygon| Method Detail |
|---|
public static boolean canCreatePoly(java.util.List<Vect> vertexList)
vertexList - list of vertices
public Vect minXY()
minXY in interface Shapepublic Vect maxXY()
maxXY in interface Shapepublic boolean containsPoint(Vect pt)
containsPoint in interface Shapepublic java.util.List<Circle> getCircles()
getCircles in interface Shapepublic java.util.List<LineSegment> getLineSegments()
getLineSegments in interface Shapepublic java.util.List<Vect> getVertices()
public Polygon rotate(Angle theta,
Vect centerOfRotation)
rotate in interface Shapetheta - angle to rotatecenterOfRotation - point to rotate around
public Polygon translate(Vect v)
translate in interface Shapev - vector to translate shape by
public static Polygon makeSquare(Vect upperLeft,
double length)
upperLeft - Vector representing upper left corner of squarelength - double length of sides
public static Polygon makeRightTriangle45(Vect upperLeft,
double length)
upperLeft - vector representing upper left corner of trianglelength - length of sides (not the hypotenuse)
public static Polygon makeRectangle(Vect upperLeft,
double width,
double height)
upperLeft - vector representing upper left corner of rectanglewidth - x dimension of rectangleheight - y dimension of rectangle
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||