org.dolben.poly
Class Polyhedron

java.lang.Object
  extended by org.dolben.poly.Polyhedron
Direct Known Subclasses:
Cuboid, Equilateral

public abstract class Polyhedron
extends java.lang.Object

Representation of a polyhedron, its vertices and faces in 3D, that can be scaled, translated and rotated. Override create() to set the vertices and faces for a particular geometric form.


Field Summary
protected  int[][] face
          Each element of the 'face' array is an array of indices into the 'vertex' array for the (co-planar) points of a face of the polyhedron, ordered such that an adjacent pair (and the first and last) are (the indices of) the end-points of an edge, and the direction of a cycle produces by the right-hand rule an outward pointing normal to the face.
protected  double[][] vertex
          Each vertex is a 3D vector from the origin of the coordinate system.
 
Constructor Summary
Polyhedron()
          Constructs a Polyhedron centered on the origin.
 
Method Summary
protected abstract  void create()
          Sets the vertex and face elements.
 double[][] getFace(int index)
          Gets an indexed face of the polyhedron, where each element of the array is a vertex of the face's polygon.
 int[] getFaceIndices(int index)
          Gets the vertex indices of an indexed face of the polyhedron.
 int getFaces()
          Gets the number of faces of the polyhedron.
 double[] getPosition()
          Gets the position of the polyhedron, a 3D vector to its center.
 double getRadius()
          Gets the radius of the polyhedron's circumsphere.
 double[] getVertex(int index)
          Gets an indexed vertex of the polyhedron.
 int getVertexCount()
          Gets the number of vertices of the polyhedron.
 double[][] getVertices()
          Gets the array of vertices of the polyhedron.
 void rotate(double[][] rotation)
          Rotates the polyhedron by the given 3D rotation matrix.
 void scale(double factor)
          Scales the polyhedron, multiplying the distance between the center and each vertex by the given argument.
 void setRadius(double radius)
          Scales the polydron, setting the radius of its circumsphere to the given argument.
 java.lang.String toString()
          Makes a String representation of the polyhedron.
 void translate(double[] displacement)
          Translates the polyhedron by the given 3D vector.
 void turnInsideOut()
          Turns the polyhedron inside-out, e.g., viewed from the inside when was viewed from the outside.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

vertex

protected double[][] vertex
Each vertex is a 3D vector from the origin of the coordinate system.


face

protected int[][] face
Each element of the 'face' array is an array of indices into the 'vertex' array for the (co-planar) points of a face of the polyhedron, ordered such that an adjacent pair (and the first and last) are (the indices of) the end-points of an edge, and the direction of a cycle produces by the right-hand rule an outward pointing normal to the face. The faces are in no special order.

Constructor Detail

Polyhedron

public Polyhedron()
Constructs a Polyhedron centered on the origin.

Method Detail

create

protected abstract void create()
Sets the vertex and face elements. Override for a concrete class.


setRadius

public void setRadius(double radius)
Scales the polydron, setting the radius of its circumsphere to the given argument.

Parameters:
radius - the new radius

getRadius

public double getRadius()
Gets the radius of the polyhedron's circumsphere.

Returns:
the radius Override if the distance between the center and the first vertex is not equal to the radius.

getPosition

public double[] getPosition()
Gets the position of the polyhedron, a 3D vector to its center.

Returns:
the postion

scale

public void scale(double factor)
Scales the polyhedron, multiplying the distance between the center and each vertex by the given argument.

Parameters:
factor - the scale factor

translate

public void translate(double[] displacement)
Translates the polyhedron by the given 3D vector.

Parameters:
displacement - the translation vector

rotate

public void rotate(double[][] rotation)
Rotates the polyhedron by the given 3D rotation matrix.

Parameters:
rotation - the rotation matrix

getVertexCount

public int getVertexCount()
Gets the number of vertices of the polyhedron.

Returns:
the number of vertices

getVertices

public double[][] getVertices()
Gets the array of vertices of the polyhedron.

Returns:
the array of vertices

getVertex

public double[] getVertex(int index)
Gets an indexed vertex of the polyhedron.

Parameters:
index - the index of the face to get
Returns:
the indexed vertex

getFaces

public int getFaces()
Gets the number of faces of the polyhedron.

Returns:
the number of faces

getFaceIndices

public int[] getFaceIndices(int index)
Gets the vertex indices of an indexed face of the polyhedron.

Parameters:
index - the index of the face to get
Returns:
the vertex indices

getFace

public double[][] getFace(int index)
Gets an indexed face of the polyhedron, where each element of the array is a vertex of the face's polygon. See the description of face for the order of the array.

Parameters:
index - the index of the face to get

turnInsideOut

public void turnInsideOut()
Turns the polyhedron inside-out, e.g., viewed from the inside when was viewed from the outside.


toString

public java.lang.String toString()
Makes a String representation of the polyhedron.

Overrides:
toString in class java.lang.Object
Returns:
the String