com.speckled.specksim.imp.motion
Class Body

java.lang.Object
  extended by com.speckled.specksim.imp.motion.Body

public class Body
extends java.lang.Object

Represents a convex body.

Author:
ryanm

Field Summary
protected  float[] faceAreas
          An array containing the areas of each face
protected  int[][] faces
          An array of 3-element arrays, containing the indices of the vertices of each triangular face
protected  Point3d[] vertices
          An array of the vertices of the body
 
Constructor Summary
Body(double[] vertexComponents)
          Construct a new Body.
 
Method Summary
static Body buildCuboid(double xLength, double yLength, double zLength)
          Build an axis-aligned cuboid body, centered on the origin
 boolean contains(Point3d point)
          Determines if the supplied point lies inside the body
 Point3d[] getBoundingBox()
          Gets the bounding box for this body
 int[][] getFaces()
          Gets the face arrays of this body.
 float getSurfaceArea()
          Gets the surface area of this body
 Point3d[] getVertices()
          Gets the vertices of this body
 float getVolume()
          Gets the volume of this body
 Point3d pointInVolume(java.util.Random random)
          Generates a point that lies inside the volume of this body.
 Point3d pointOnSurface(java.util.Random random)
          Generates a random point that lies on the surface of this body.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

vertices

protected final Point3d[] vertices
An array of the vertices of the body


faces

protected final int[][] faces
An array of 3-element arrays, containing the indices of the vertices of each triangular face


faceAreas

protected final float[] faceAreas
An array containing the areas of each face

Constructor Detail

Body

public Body(double[] vertexComponents)
Construct a new Body. A convex hull will be constructed around the points supplied.

Parameters:
vertexComponents - The vertices of this body in [ x1, y1, z1, x2, y2, z3, ... , yn, zn ] format
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getSurfaceArea

public float getSurfaceArea()
Gets the surface area of this body

Returns:
The surface area

getVolume

public float getVolume()
Gets the volume of this body

Returns:
The volume

contains

public boolean contains(Point3d point)
Determines if the supplied point lies inside the body

Parameters:
point - The point to test for inclusion
Returns:
true if the point lies inside the body, false otherwise

getBoundingBox

public Point3d[] getBoundingBox()
Gets the bounding box for this body

Returns:
A two element array of Vectors. The first element is the minimal corner of the bounding box, the second being the maximal

pointOnSurface

public Point3d pointOnSurface(java.util.Random random)
Generates a random point that lies on the surface of this body. Points are distributed evenly over the surface area.

Parameters:
random - The random number generator to use
Returns:
A point that lies on the surface of this body

pointInVolume

public Point3d pointInVolume(java.util.Random random)
Generates a point that lies inside the volume of this body. Points will be evenly distributed.

Parameters:
random - The random number generator to use
Returns:
A point on the inside of this body

getVertices

public Point3d[] getVertices()
Gets the vertices of this body

Returns:
the vertices

getFaces

public int[][] getFaces()
Gets the face arrays of this body.

Returns:
An array of int arrays, each listing the vertices of a face

buildCuboid

public static Body buildCuboid(double xLength,
                               double yLength,
                               double zLength)
Build an axis-aligned cuboid body, centered on the origin

Parameters:
xLength - The length of the cuboid on the x-axis
yLength - The length of the cuboid on the y-axis
zLength - The length of the cuboid on the z-axis
Returns:
A cuboid body