vooga.physicsEngine.geometry.shapes
Class Polygon

java.lang.Object
  extended by vooga.physicsEngine.geometry.shapes.Polygon
All Implemented Interfaces:
Shape

public class Polygon
extends java.lang.Object
implements Shape

Represents a general polygon, represented by an ordered set of vertices. The coordinates should be such that that (0,0) is the centroid of the shape.

Author:
Peng Shi, Sami Boghos

Constructor Summary
Polygon(Vector2f[] vertices)
          Create new Polygon using list of verticies; note that (0,0) will be the centroid.
 
Method Summary
 java.awt.image.BufferedImage createBufferedImage(double angularPosition)
          Creates a BufferedImage representing the given Shape.
 BoundingBox getBoundingBox()
          Returns the bounding box of a shape.
 Vector2f getCentroid()
           
 int getNumVertices()
          Return the number of vertices
 double getR2IntegralEstimate()
          Obtain an estimate of the integral of R^2 over the whole shape, where R is the distance between each point and the centroid.
 Vector2f getSmallestCorner()
           
 Vector2f getVertex(int x)
          Return the vector of the vertex at position x
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Polygon

public Polygon(Vector2f[] vertices)
Create new Polygon using list of verticies; note that (0,0) will be the centroid.

Parameters:
vertices - List of vectors representing the vertices of the polygon
Method Detail

getNumVertices

public int getNumVertices()
Return the number of vertices

Returns:
number of vertices

getVertex

public Vector2f getVertex(int x)
Return the vector of the vertex at position x

Parameters:
x - position of vector
Returns:
vector at position x

getBoundingBox

public BoundingBox getBoundingBox()
Description copied from interface: Shape
Returns the bounding box of a shape. The bounding box always contains the shape until all rotations.

Specified by:
getBoundingBox in interface Shape
Returns:

createBufferedImage

public java.awt.image.BufferedImage createBufferedImage(double angularPosition)
Description copied from interface: Shape
Creates a BufferedImage representing the given Shape. This image will have the same bounding box as the given shape. The image will have black outline and white interior. This is mostly for simple games and internal testing.

Specified by:
createBufferedImage in interface Shape
Returns:

getR2IntegralEstimate

public double getR2IntegralEstimate()
Description copied from interface: Shape
Obtain an estimate of the integral of R^2 over the whole shape, where R is the distance between each point and the centroid. This is used to compute a reasonable estimate for the moment of inertia.

Specified by:
getR2IntegralEstimate in interface Shape
Returns:

getCentroid

public Vector2f getCentroid()
Specified by:
getCentroid in interface Shape
Returns:
the relative Shape coordinate of the centroid

getSmallestCorner

public Vector2f getSmallestCorner()
Specified by:
getSmallestCorner in interface Shape
Returns:
the relative Shape coordinate of the top left corner of the tightest bounding box (this is needed for translating the game position coordinate--based on the smallest corner--to the physics engine coordinate--based on the centroid.