sim.physics2D.shape
Class Polygon

java.lang.Object
  extended by sim.physics2D.shape.Shape
      extended by sim.physics2D.shape.Polygon
Direct Known Subclasses:
Rectangle

public abstract class Polygon
extends Shape

Polygons represents any convex multi-sided object. Convex means that every angle measured between the insides of two edges must be less than 180 degrees. To create a new polygon, create a new class that inherits from polygon and implement the abstract functions based on the descriptions given below. Use rectangle as a reference.


Field Summary
protected  DenseMatrix edges
           
protected  double maxXDistanceFromCenter
           
protected  double maxYDistanceFromCenter
           
protected  DenseMatrix normals
           
protected  DenseMatrix scale
           
protected  DenseMatrix vertices
           
 
Fields inherited from class sim.physics2D.shape.Shape
index, paint, stationary
 
Constructor Summary
Polygon()
           
Polygon(boolean stationary)
           
 
Method Summary
 void draw(java.lang.Object object, java.awt.Graphics2D graphics, DrawInfo2D info)
          Display the polygon
 Double2D[] getEdges()
          Returns a list of the normalized edges in a clockwise direction.
 double getMaxXDistanceFromCenter()
           
 double getMaxYDistanceFromCenter()
           
 Double2D[] getNormals()
          Returns a list of the unit normals in a clockwise direction.
static int[] getRow(int row, DenseMatrix mat)
          Returns a row of the DenseMatrix rounded to integers
 Double2D[] getVertices()
          Returns a list of the vertexes in a clockwise direction with positive Y pointing up (vs.
abstract  void initEdges()
          Set up the edges DenseMatrix.
abstract  void initNormals()
          Set up the normals DenseMatrix.
abstract  void initVertices()
          Set up the vertices DenseMatrix.
static DenseMatrix rotationMatrix2D(double theta)
          Returns a DenseMatrix in homogenous coordinates to rotate a 2 dimensional rigid body given the angle theta (in radians)
static DenseMatrix rotationTranslationMatrix2D(double theta, Double2D translation)
          Returns a DenseMatrix in homogenous coordinates to rotate and translate a 2 dimensional rigid body given the angle theta (in radians) and a translation vector
 
Methods inherited from class sim.physics2D.shape.Shape
calcMaxDistances, getMassMomentOfInertia, getOrientation, getPaint, getPosition, setIndex, setPaint
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxXDistanceFromCenter

protected double maxXDistanceFromCenter

maxYDistanceFromCenter

protected double maxYDistanceFromCenter

vertices

protected DenseMatrix vertices

edges

protected DenseMatrix edges

normals

protected DenseMatrix normals

scale

protected DenseMatrix scale
Constructor Detail

Polygon

public Polygon(boolean stationary)

Polygon

public Polygon()
Method Detail

getVertices

public Double2D[] getVertices()
Returns a list of the vertexes in a clockwise direction with positive Y pointing up (vs. pointing down as on a computer screen)


getEdges

public Double2D[] getEdges()
Returns a list of the normalized edges in a clockwise direction. The starting vertex of the edge must be the vertex with the corresponding index. For example, edge 0 goes from vertex 0 to vertex 1


getNormals

public Double2D[] getNormals()
Returns a list of the unit normals in a clockwise direction. Each normal's index must correspond to its edge's index. For example, the normal to edge 0 must have index 0


initVertices

public abstract void initVertices()
Set up the vertices DenseMatrix. The vertices DenseMatrix gives the homogenous coordinates of the vertices centered around 0,0. They must be defined clockwise.


initEdges

public abstract void initEdges()
Set up the edges DenseMatrix. The edges DenseMatrix gives the edge vectors in homogenous coordinates between the vertices. The number of the edge should correspond to the number of the vertex from which the vector points (i.e. edge 0 points from vertex 0 to vertex 1). Edges should point clockwise and must be normalized.


initNormals

public abstract void initNormals()
Set up the normals DenseMatrix. The normals DenseMatrix gives the normal vectors in homogenous coordinates. The numbers of the normals must correspond to the edge to which the normal is perpendicular to (i.e. normal 0 points out from edge 0). The normals must be of unit length


draw

public void draw(java.lang.Object object,
                 java.awt.Graphics2D graphics,
                 DrawInfo2D info)
Display the polygon

Specified by:
draw in class Shape

getMaxXDistanceFromCenter

public double getMaxXDistanceFromCenter()
Specified by:
getMaxXDistanceFromCenter in class Shape

getMaxYDistanceFromCenter

public double getMaxYDistanceFromCenter()
Specified by:
getMaxYDistanceFromCenter in class Shape

rotationMatrix2D

public static DenseMatrix rotationMatrix2D(double theta)
Returns a DenseMatrix in homogenous coordinates to rotate a 2 dimensional rigid body given the angle theta (in radians)


rotationTranslationMatrix2D

public static DenseMatrix rotationTranslationMatrix2D(double theta,
                                                      Double2D translation)
Returns a DenseMatrix in homogenous coordinates to rotate and translate a 2 dimensional rigid body given the angle theta (in radians) and a translation vector


getRow

public static int[] getRow(int row,
                           DenseMatrix mat)
Returns a row of the DenseMatrix rounded to integers