smithers.java3d
Class Polygon3D

java.lang.Object
  extended by smithers.java3d.Polygon3D

public class Polygon3D
extends java.lang.Object

Represents a polygon in 3D space. This class represents a polygon by a sequence of vertices. No guarantee is made that these are coplanar (in fact, such a guarantee would be impossible in the presence of floating-point rounding errors), but most uses of this class will only make sense for (almost) planar polgons.


Constructor Summary
Polygon3D()
          Constructs a new, empty Polygon3D.
Polygon3D(float[]... points)
          Constructs a new Polygon3D from the specified points.
Polygon3D(int size)
          Constructs a new, empty Polygon3D.
 
Method Summary
 void add(float[] point)
          Adds a new point to the end of the array of vertices.
 float[][] points()
          Returns the array of points which make up this polygon.
 Polygon3D scale(float factor)
          Scales the polygon by the given factor.
 float[] vertexCentroid()
          Computes the "centre" of this polygon.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Polygon3D

public Polygon3D()
Constructs a new, empty Polygon3D.


Polygon3D

public Polygon3D(int size)
Constructs a new, empty Polygon3D.

Parameters:
size - the number of points the polygon should have space for

Polygon3D

public Polygon3D(float[]... points)
Constructs a new Polygon3D from the specified points.

Parameters:
points - the vertices of the new polygon
Method Detail

add

public void add(float[] point)
Adds a new point to the end of the array of vertices.

Parameters:
point - the new point

points

public float[][] points()
Returns the array of points which make up this polygon.

Returns:
the array of vertices of the polygon

vertexCentroid

public float[] vertexCentroid()
Computes the "centre" of this polygon. The point returned is the centre of mass of the vertices of the polygon.

Returns:
the centroid of the polygon's vertices

scale

public Polygon3D scale(float factor)
Scales the polygon by the given factor.

Parameters:
factor - the scale factor to use
Returns:
the scaled polygon