Package com.jme3.math

# Class Triangle

All Implemented Interfaces:
`Collidable`, `Savable`, `Serializable`, `Cloneable`

public class Triangle extends AbstractTriangle implements Savable, Cloneable, Serializable
Describes a triangle in terms of its vertex locations, with auxiliary storage for its centroid, normal vector, projection, and index.
• ## Constructor Summary

Constructors
Constructor
Description
`Triangle()`
Instantiate a zero-size triangle at the origin.
```Triangle(Vector3f p1, Vector3f p2, Vector3f p3)```
Instantiates a triangle with the specified vertex locations.
• ## Method Summary

Modifier and Type
Method
Description
`void`
`calculateCenter()`
Recalculates the stored centroid based on the current vertex locations.
`void`
`calculateNormal()`
Recalculates the stored normal based on the current vertex locations.
`Triangle`
`clone()`
Creates a copy of this triangle.
`static Vector3f`
```computeTriangleNormal(Vector3f v1, Vector3f v2, Vector3f v3, Vector3f store)```

`Vector3f`
`get(int i)`
Accesses the location of the indexed vertex.
`Vector3f`
`get1()`
Accesses the location of the first vertex.
`Vector3f`
`get2()`
Accesses the location of the 2nd vertex.
`Vector3f`
`get3()`
Accesses the location of the 3rd vertex.
`Vector3f`
`getCenter()`
Accesses the stored centroid (the average of the 3 vertex locations) calculating it if it is null.
`int`
`getIndex()`
Returns the index of this triangle, used to identify it in an OBBTree.
`Vector3f`
`getNormal()`
Accesses the stored normal, updating it if it is null.
`float`
`getProjection()`
Returns the projection of the vertices relative to the line origin.
`void`
`read(JmeImporter importer)`
De-serializes this triangle from the specified importer, for example when loading from a J3O file.
`void`
```set(int i, float x, float y, float z)```
Alters the location of the indexed vertex and deletes the stored centroid and normal.
`void`
```set(int i, Vector3f point)```
Alters the location of the indexed vertex and deletes the stored centroid and normal.
`void`
```set(Vector3f v1, Vector3f v2, Vector3f v3)```
Alters the locations of all 3 vertices and deletes the stored centroid and normal.
`void`
`set1(Vector3f v)`
Alters the location of the first vertex and deletes the stored centroid and normal.
`void`
`set2(Vector3f v)`
Alters the location of the 2nd vertex and deletes the stored centroid and normal.
`void`
`set3(Vector3f v)`
Alters the location of the 3rd vertex and deletes the stored centroid and normal.
`void`
`setCenter(Vector3f center)`
Alters the stored centroid without affecting the stored normal or any vertex locations.
`void`
`setIndex(int index)`
Alters the index of this triangle, used to identify it in an OBBTree.
`void`
`setNormal(Vector3f normal)`
Alters the stored normal without affecting the stored centroid or any vertex locations.
`void`
`setProjection(float projection)`
Alters the projection of the vertices relative to the line origin.
`void`
`write(JmeExporter e)`
Serializes this triangle to the specified exporter, for example when saving to a J3O file.

### Methods inherited from class com.jme3.math.AbstractTriangle

`collideWith`

### Methods inherited from class java.lang.Object

`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ## Constructor Details

• ### Triangle

public Triangle()
Instantiate a zero-size triangle at the origin.
• ### Triangle

public Triangle(Vector3f p1, Vector3f p2, Vector3f p3)
Instantiates a triangle with the specified vertex locations. Vertices should be listed in the desired winding order, typically counter-clockwise.
Parameters:
`p1` - the location of the first vertex (not null, unaffected)
`p2` - the location of the 2nd vertex (not null, unaffected)
`p3` - the location of the 3rd vertex (not null, unaffected)
• ## Method Details

• ### get

public Vector3f get(int i)
Accesses the location of the indexed vertex.
Parameters:
`i` - the index of the vertex to access (0, 1, or 2)
Returns:
a pre-existing location vector, or null if the index is invalid
• ### get1

public Vector3f get1()
Accesses the location of the first vertex.
Specified by:
`get1` in class `AbstractTriangle`
Returns:
the pre-existing location vector (not null)
• ### get2

public Vector3f get2()
Accesses the location of the 2nd vertex.
Specified by:
`get2` in class `AbstractTriangle`
Returns:
the pre-existing location vector (not null)
• ### get3

public Vector3f get3()
Accesses the location of the 3rd vertex.
Specified by:
`get3` in class `AbstractTriangle`
Returns:
the pre-existing location vector (not null)
• ### set

public void set(int i, Vector3f point)
Alters the location of the indexed vertex and deletes the stored centroid and normal.
Parameters:
`i` - the index of the vertex to alter (0, 1, or 2)
`point` - the desired location (not null, unaffected)
• ### set

public void set(int i, float x, float y, float z)
Alters the location of the indexed vertex and deletes the stored centroid and normal.
Parameters:
`i` - the index of the vertex to alter (0, 1, or 2)
`x` - the desired X coordinate
`y` - the desired Y coordinate
`z` - the desired Z coordinate
• ### set1

public void set1(Vector3f v)
Alters the location of the first vertex and deletes the stored centroid and normal.
Parameters:
`v` - the desired location (not null, unaffected)
• ### set2

public void set2(Vector3f v)
Alters the location of the 2nd vertex and deletes the stored centroid and normal.
Parameters:
`v` - the desired location (not null, unaffected)
• ### set3

public void set3(Vector3f v)
Alters the location of the 3rd vertex and deletes the stored centroid and normal.
Parameters:
`v` - the desired location (not null, unaffected)
• ### set

public void set(Vector3f v1, Vector3f v2, Vector3f v3)
Alters the locations of all 3 vertices and deletes the stored centroid and normal.
Specified by:
`set` in class `AbstractTriangle`
Parameters:
`v1` - the desired location of the first vertex (not null, unaffected)
`v2` - the desired location of the 2nd vertex (not null, unaffected)
`v3` - the desired location of the 3rd vertex (not null, unaffected)
• ### calculateCenter

public void calculateCenter()
Recalculates the stored centroid based on the current vertex locations.
• ### calculateNormal

public void calculateNormal()
Recalculates the stored normal based on the current vertex locations.
• ### getCenter

public Vector3f getCenter()
Accesses the stored centroid (the average of the 3 vertex locations) calculating it if it is null.
Returns:
the coordinates of the center (an internal vector subject to re-use)
• ### setCenter

public void setCenter(Vector3f center)
Alters the stored centroid without affecting the stored normal or any vertex locations.
Parameters:
`center` - the desired value (alias created if not null)
• ### getNormal

public Vector3f getNormal()
Accesses the stored normal, updating it if it is null.
Returns:
unit normal vector (an internal vector subject to re-use)
• ### setNormal

public void setNormal(Vector3f normal)
Alters the stored normal without affecting the stored centroid or any vertex locations.
Parameters:
`normal` - the desired value (alias created if not null)
• ### getProjection

public float getProjection()
Returns the projection of the vertices relative to the line origin.
Returns:
the stored projection value
• ### setProjection

public void setProjection(float projection)
Alters the projection of the vertices relative to the line origin.
Parameters:
`projection` - the desired projection value
• ### getIndex

public int getIndex()
Returns the index of this triangle, used to identify it in an OBBTree.
Returns:
the stored index
• ### setIndex

public void setIndex(int index)
Alters the index of this triangle, used to identify it in an OBBTree.
Parameters:
`index` - the desired index
• ### computeTriangleNormal

public static Vector3f computeTriangleNormal(Vector3f v1, Vector3f v2, Vector3f v3, Vector3f store)
• ### write

public void write(JmeExporter e) throws IOException
Serializes this triangle to the specified exporter, for example when saving to a J3O file.
Specified by:
`write` in interface `Savable`
Parameters:
`e` - (not null)
Throws:
`IOException` - from the exporter

public void read(JmeImporter importer) throws IOException
De-serializes this triangle from the specified importer, for example when loading from a J3O file.
Specified by:
`read` in interface `Savable`
Parameters:
`importer` - (not null)
Throws:
`IOException` - from the importer
• ### clone

public Triangle clone()
Creates a copy of this triangle.
Overrides:
`clone` in class `Object`
Returns:
a new instance, equivalent to this one