net.phys2d.raw.shapes
Class ConvexPolygon

java.lang.Object
  extended bynet.phys2d.raw.shapes.AbstractShape
      extended bynet.phys2d.raw.shapes.Polygon
          extended bynet.phys2d.raw.shapes.ConvexPolygon
All Implemented Interfaces:
DynamicShape, Shape

public class ConvexPolygon
extends Polygon
implements DynamicShape

Class representing a convex and closed polygon as a list of vertices in counterclockwise order. Convexity is maintained by a check in the constructor after which the polygon becomes immutable.


Field Summary
 
Fields inherited from class net.phys2d.raw.shapes.Polygon
area, centroid, vertices
 
Fields inherited from class net.phys2d.raw.shapes.AbstractShape
bounds
 
Constructor Summary
ConvexPolygon(ROVector2f[] vertices)
          Construct the convex polygon with a list of vertices sorted in counterclockwise order.
 
Method Summary
 boolean contains(Vector2f p)
          Test whether or not the point p is in this polygon in O(n), where n is the number of vertices in this polygon.
 ROVector2f getNearestPoint(ROVector2f p)
          Get point on this polygon's hull that is closest to p.
 float getSurfaceFactor()
          Some factor based on the edges length of the shape
 boolean isConvex()
          Because convexness is checked at construction we can always return true here.
 
Methods inherited from class net.phys2d.raw.shapes.Polygon
computeArea, computeBoundingCircleRadius, computeCentroid, contains, getArea, getCentroid, getCentroid, getVertices, getVertices
 
Methods inherited from class net.phys2d.raw.shapes.AbstractShape
getBounds
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.phys2d.raw.shapes.Shape
getBounds
 

Constructor Detail

ConvexPolygon

public ConvexPolygon(ROVector2f[] vertices)
Construct the convex polygon with a list of vertices sorted in counterclockwise order. Note that all the vector values will be copied. Throws an exception when too few vertices are given (< 3) and when the supplied vertices are not convex. Polygons with area = 0, will be reported as non-convex too.

Parameters:
vertices - Vertices sorted in counterclockwise order
Method Detail

isConvex

public boolean isConvex()
Because convexness is checked at construction we can always return true here.

Overrides:
isConvex in class Polygon
Returns:
true iff this polygon is convex
See Also:
Polygon.isConvex()

contains

public boolean contains(Vector2f p)
Test whether or not the point p is in this polygon in O(n), where n is the number of vertices in this polygon.

Parameters:
p - The point to be tested for inclusion in this polygon
Returns:
true iff the p is in this polygon (not on a border)

getNearestPoint

public ROVector2f getNearestPoint(ROVector2f p)
Get point on this polygon's hull that is closest to p. TODO: make this thing return a negative value when it is contained in the polygon

Overrides:
getNearestPoint in class Polygon
Parameters:
p - The point to search the closest point for
Returns:
the nearest point on this vertex' hull

getSurfaceFactor

public float getSurfaceFactor()
Description copied from interface: Shape
Some factor based on the edges length of the shape

Specified by:
getSurfaceFactor in interface Shape
Overrides:
getSurfaceFactor in class Polygon
See Also:
Shape.getSurfaceFactor()