com.threerings.math
Class Triangle

java.lang.Object
  extended by com.threerings.math.Triangle
All Implemented Interfaces:
Exportable

public final class Triangle
extends Object
implements Exportable

A triangle defined by three vertices (in CCW winding order).


Field Summary
static Comparator<Triangle> X_COMPARATOR
          Compares triangles based on the x coordinates of their centers.
static Comparator<Triangle> Y_COMPARATOR
          Compares triangles based on the y coordinates of their centers.
static Comparator<Triangle> Z_COMPARATOR
          Compares triangles based on the z coordinates of their centers.
 
Constructor Summary
Triangle()
          Creates a triangle whose vertices are zero vectors.
Triangle(Triangle other)
          Copy constructor.
Triangle(Vector3f v1, Vector3f v2, Vector3f v3)
          Creates a triangle from the values contained in the supplied objects.
 
Method Summary
 Triangle flipLocal()
          Flips the orientation of the triangle by swapping the second and third vertices.
 Vector3f getCenter()
          Returns the center of the triangle as a new vector.
 float getCenterX()
          Returns the x coordinate of the triangle's center.
 float getCenterY()
          Returns the y coordinate of the triangle's center.
 float getCenterZ()
          Returns the z coordinate of the triangle's center.
 Vector3f getFirstVertex()
          Returns a reference to the triangle's first vertex.
 boolean getIntersection(Ray3D ray, Vector3f result)
          Computes the intersection of the supplied ray with this triangle, placing the result in the given vector (if the ray intersects).
 Vector3f getSecondVertex()
          Returns a reference to the triangle's second vertex.
 Vector3f getThirdVertex()
          Returns a reference to the triangle's third vertex.
 Vector3f getVertex(int idx)
          Returns a reference to the vertex at the specified index.
 Triangle set(Triangle other)
          Sets the vertices of the triangle to those of the specified other triangle.
 Triangle set(Vector3f v1, Vector3f v2, Vector3f v3)
          Sets the vertices of the triangle to those contained in the supplied objects.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

X_COMPARATOR

public static final Comparator<Triangle> X_COMPARATOR
Compares triangles based on the x coordinates of their centers.


Y_COMPARATOR

public static final Comparator<Triangle> Y_COMPARATOR
Compares triangles based on the y coordinates of their centers.


Z_COMPARATOR

public static final Comparator<Triangle> Z_COMPARATOR
Compares triangles based on the z coordinates of their centers.

Constructor Detail

Triangle

public Triangle(Vector3f v1,
                Vector3f v2,
                Vector3f v3)
Creates a triangle from the values contained in the supplied objects.


Triangle

public Triangle(Triangle other)
Copy constructor.


Triangle

public Triangle()
Creates a triangle whose vertices are zero vectors.

Method Detail

getFirstVertex

public Vector3f getFirstVertex()
Returns a reference to the triangle's first vertex.


getSecondVertex

public Vector3f getSecondVertex()
Returns a reference to the triangle's second vertex.


getThirdVertex

public Vector3f getThirdVertex()
Returns a reference to the triangle's third vertex.


getVertex

public Vector3f getVertex(int idx)
Returns a reference to the vertex at the specified index.


getCenter

public Vector3f getCenter()
Returns the center of the triangle as a new vector.


getCenterX

public float getCenterX()
Returns the x coordinate of the triangle's center.


getCenterY

public float getCenterY()
Returns the y coordinate of the triangle's center.


getCenterZ

public float getCenterZ()
Returns the z coordinate of the triangle's center.


flipLocal

public Triangle flipLocal()
Flips the orientation of the triangle by swapping the second and third vertices.

Returns:
a reference to this triangle, for chaining.

set

public Triangle set(Triangle other)
Sets the vertices of the triangle to those of the specified other triangle.

Returns:
a reference to this triangle, for chaining.

set

public Triangle set(Vector3f v1,
                    Vector3f v2,
                    Vector3f v3)
Sets the vertices of the triangle to those contained in the supplied objects.

Returns:
a reference to this triangle, for chaining.

getIntersection

public boolean getIntersection(Ray3D ray,
                               Vector3f result)
Computes the intersection of the supplied ray with this triangle, placing the result in the given vector (if the ray intersects). Uses the algorithm described in Tomas Moller and Ben Trumbore's Fast, Minimum Storage Ray/Triangle Intersection.

Returns:
true if the ray intersects this triangle (in which case the result will contain the point of intersection), false if not.


Copyright © 2011. All Rights Reserved.