NASA World Wind
gov.nasa.worldwind.geom

## Class Triangle

• ```public class Triangle
extends Object```
Provides operations on triangles.
• ### Nested Class Summary

Nested Classes
Modifier and Type Class and Description
`protected static class ` `Triangle.TriangleIntersection`
Defines a line segment representing the intersection of a line with and in the plane of a triangle.
• ### Constructor Summary

Constructors
Constructor and Description
```Triangle(Vec4 a, Vec4 b, Vec4 c)```
Construct a triangle from three counter-clockwise ordered vertices.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`protected static Triangle.TriangleIntersection` ```compute_intervals_isectline(Vec4[] v, double vv0, double vv1, double vv2, double d0, double d1, double d2, double d0d1, double d0d2)```
`boolean` `contains(Vec4 p)`
Indicates whether a specified point is on the triangle.
`protected static boolean` ```coplanarTriangles(Vec4 n, Vec4[] v, Vec4[] u)```
`protected static boolean` ```edgeEdgeTest(double[] v0, double[] u0, double[] u1, int i0, int i1, double ax, double ay)```
`static void` ```expandTriangleFan(List<Integer> indices, FloatBuffer inBuf, FloatBuffer outBuf)```
Expands a buffer of indexed triangle fan vertices to a buffer of non-indexed general-triangle vertices.
`static void` ```expandTriangleFan(List<Integer> indices, IntBuffer outBuf)```
`static void` ```expandTriangles(List<Integer> indices, FloatBuffer inBuf, FloatBuffer outBuf)```
Expands a buffer of indexed triangle vertices to a buffer of non-indexed triangle vertices.
`static void` ```expandTriangles(List<Integer> indices, IntBuffer outBuf)```
`static void` ```expandTriangleStrip(List<Integer> indices, FloatBuffer inBuf, FloatBuffer outBuf)```
Expands a buffer of indexed triangle strip vertices to a buffer of non-indexed general-triangle vertices.
`static void` ```expandTriangleStrip(List<Integer> indices, IntBuffer outBuf)```
`Vec4` `getA()`
Returns the first vertex.
`Vec4` `getB()`
Returns the second vertex.
`Vec4` `getC()`
Returns the third vertex.
`Vec4` `intersect(Line line)`
Determine the intersection of the triangle with a specified line.
`static Intersection` ```intersect(Line line, double vax, double vay, double vaz, double vbx, double vby, double vbz, double vcx, double vcy, double vcz)```
Determines the intersection of a specified line with a triangle specified by individual coordinates.
`static Intersection` ```intersect(Line line, Vec4 a, Vec4 b, Vec4 c)```
Determines the intersection of a specified line with a specified triangle.
`protected static Triangle.TriangleIntersection` ```intersect(Vec4 v0, Vec4 v1, Vec4 v2, double vv0, double vv1, double vv2, double d0, double d1, double d2)```
`static List<Intersection>` ```intersectTriangles(Line line, FloatBuffer vertices)```
Compute the intersections of a line with a collection of triangles.
`static List<Intersection>` ```intersectTriangles(Line line, FloatBuffer vertices, IntBuffer indices)```
Compute the intersections of a line with a collection of triangles.
`static int` ```intersectTriangles(Vec4[] v, Vec4[] u, Vec4[] intersectionVertices)```
Intersects two triangles and returns their intersection vertices.
`static List<Intersection>` ```intersectTriangleTypes(Line line, FloatBuffer vertices, IntBuffer indices, int triangleType)```
Compute the intersections of a line with a triangle collection.
`static List<Intersection>` ```intersectTriFan(Line line, FloatBuffer vertices, IntBuffer indices)```
Compute the intersections of a line with a triangle fan.
`static List<Intersection>` ```intersectTriFan(Line line, Vec4[] vertices, IntBuffer indices)```
Compute the intersections of a line with a triangle fan.
`static List<Intersection>` ```intersectTriStrip(Line line, FloatBuffer vertices, IntBuffer indices)```
Compute the intersections of a line with a triangle strip.
`static List<Intersection>` ```intersectTriStrip(Line line, Vec4[] vertices, IntBuffer indices)```
Compute the intersections of a line with a triangle strip.
`protected static boolean` ```pointInTri(double[] v0, double[] u0, double[] u1, double[] u2, int i0, int i1)```
`String` `toString()`
`protected static boolean` ```triangleEdgeTest(double[] v0, double[] v1, double[] u0, double[] u1, double[] u2, int i0, int i1)```
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Constructor Detail

• #### Triangle

```public Triangle(Vec4 a,
Vec4 b,
Vec4 c)```
Construct a triangle from three counter-clockwise ordered vertices. The front face of the triangle is determined by the right-hand rule.
Parameters:
`a` - the first vertex.
`b` - the second vertex.
`c` - the third vertex.
Throws:
`IllegalArgumentException` - if any vertex is null.
• ### Method Detail

• #### compute_intervals_isectline

```protected static Triangle.TriangleIntersection compute_intervals_isectline(Vec4[] v,
double vv0,
double vv1,
double vv2,
double d0,
double d1,
double d2,
double d0d1,
double d0d2)```
• #### contains

`public boolean contains(Vec4 p)`
Indicates whether a specified point is on the triangle.
Parameters:
`p` - the point to test. If null, the method returns false.
Returns:
true if the point is on the triangle, otherwise false.
• #### coplanarTriangles

```protected static boolean coplanarTriangles(Vec4 n,
Vec4[] v,
Vec4[] u)```
• #### edgeEdgeTest

```protected static boolean edgeEdgeTest(double[] v0,
double[] u0,
double[] u1,
int i0,
int i1,
double ax,
double ay)```
• #### expandTriangleFan

```public static void expandTriangleFan(List<Integer> indices,
FloatBuffer inBuf,
FloatBuffer outBuf)```
Expands a buffer of indexed triangle fan vertices to a buffer of non-indexed general-triangle vertices.
Parameters:
`indices` - the triangle indices.
`inBuf` - the vertex buffer the indices refer to, in the order x, y, z, x, y, z, ...
`outBuf` - the buffer in which to place the expanded triangle vertices. The buffer must have a limit sufficient to hold the output vertices.
Throws:
`IllegalArgumentException` - if the index list or the input or output buffer is null, or if the output buffer size is insufficient.
• #### expandTriangleFan

```public static void expandTriangleFan(List<Integer> indices,
IntBuffer outBuf)```
• #### expandTriangles

```public static void expandTriangles(List<Integer> indices,
FloatBuffer inBuf,
FloatBuffer outBuf)```
Expands a buffer of indexed triangle vertices to a buffer of non-indexed triangle vertices.
Parameters:
`indices` - the triangle indices.
`inBuf` - the vertex buffer the indices refer to, in the order x, y, z, x, y, z, ...
`outBuf` - the buffer in which to place the expanded triangle vertices. The buffer must have a limit sufficient to hold the output vertices.
Throws:
`IllegalArgumentException` - if the index list or the input or output buffer is null, or if the output buffer size is insufficient.
• #### expandTriangles

```public static void expandTriangles(List<Integer> indices,
IntBuffer outBuf)```
• #### expandTriangleStrip

```public static void expandTriangleStrip(List<Integer> indices,
FloatBuffer inBuf,
FloatBuffer outBuf)```
Expands a buffer of indexed triangle strip vertices to a buffer of non-indexed general-triangle vertices.
Parameters:
`indices` - the triangle indices.
`inBuf` - the vertex buffer the indices refer to, in the order x, y, z, x, y, z, ...
`outBuf` - the buffer in which to place the expanded triangle vertices. The buffer must have a limit sufficient to hold the output vertices.
Throws:
`IllegalArgumentException` - if the index list or the input or output buffer is null, or if the output buffer size is insufficient.
• #### expandTriangleStrip

```public static void expandTriangleStrip(List<Integer> indices,
IntBuffer outBuf)```
• #### getA

`public Vec4 getA()`
Returns the first vertex.
Returns:
the first vertex.
• #### getB

`public Vec4 getB()`
Returns the second vertex.
Returns:
the second vertex.
• #### getC

`public Vec4 getC()`
Returns the third vertex.
Returns:
the third vertex.
• #### intersect

`public Vec4 intersect(Line line)`
Determine the intersection of the triangle with a specified line.
Parameters:
`line` - the line to test.
Returns:
the point of intersection if the line intersects the triangle, otherwise null.
Throws:
`IllegalArgumentException` - if the line is null.
• #### intersect

```public static Intersection intersect(Line line,
double vax,
double vay,
double vaz,
double vbx,
double vby,
double vbz,
double vcx,
double vcy,
double vcz)```
Determines the intersection of a specified line with a triangle specified by individual coordinates.
Parameters:
`line` - the line to test.
`vax` - the X coordinate of the first vertex of the triangle.
`vay` - the Y coordinate of the first vertex of the triangle.
`vaz` - the Z coordinate of the first vertex of the triangle.
`vbx` - the X coordinate of the second vertex of the triangle.
`vby` - the Y coordinate of the second vertex of the triangle.
`vbz` - the Z coordinate of the second vertex of the triangle.
`vcx` - the X coordinate of the third vertex of the triangle.
`vcy` - the Y coordinate of the third vertex of the triangle.
`vcz` - the Z coordinate of the third vertex of the triangle.
Returns:
the point of intersection if the line intersects the triangle, otherwise null.
• #### intersect

```public static Intersection intersect(Line line,
Vec4 a,
Vec4 b,
Vec4 c)```
Determines the intersection of a specified line with a specified triangle. The triangle is specified by three points ordered counterclockwise. The triangle's front face is determined by the right-hand rule.
Parameters:
`line` - the line to test.
`a` - the first vertex of the triangle.
`b` - the second vertex of the triangle.
`c` - the third vertex of the triangle.
Returns:
the point of intersection if the line intersects the triangle, otherwise null.
Throws:
`IllegalArgumentException` - if the line or any of the triangle vertices is null.
• #### intersect

```protected static Triangle.TriangleIntersection intersect(Vec4 v0,
Vec4 v1,
Vec4 v2,
double vv0,
double vv1,
double vv2,
double d0,
double d1,
double d2)```
• #### intersectTriangles

```public static List<Intersection> intersectTriangles(Line line,
FloatBuffer vertices)```
Compute the intersections of a line with a collection of triangles.
Parameters:
`line` - the line to intersect.
`vertices` - the triangles, arranged in a buffer as GL_TRIANGLES (9 floats per triangle).
Returns:
the list of intersections with the line and the triangles, or null if there are no intersections.
Throws:
`IllegalArgumentException` - if the line or vertex buffer is null.
• #### intersectTriangles

```public static List<Intersection> intersectTriangles(Line line,
FloatBuffer vertices,
IntBuffer indices)```
Compute the intersections of a line with a collection of triangles.
Parameters:
`line` - the line to intersect.
`vertices` - the triangles, arranged in a buffer as GL_TRIANGLES (9 floats per triangle).
`indices` - the indices forming the triangles.
Returns:
the list of intersections with the line and the triangle fan, or null if there are no intersections.
Throws:
`IllegalArgumentException` - if the line, vertex buffer or index buffer is null.
• #### intersectTriangles

```public static int intersectTriangles(Vec4[] v,
Vec4[] u,
Vec4[] intersectionVertices)```
Intersects two triangles and returns their intersection vertices.
Parameters:
`v` - the Cartesian coordinates of the first triangle.
`u` - the Cartesian coordinates of the second triangle.
`intersectionVertices` - a pre-allocated two-element array in which the intersection vertices, if any, are returned.
Returns:
-1 if there is no intersection, 1 if there is an intersection, or 0 if the triangles are co-planar.
• #### intersectTriangleTypes

```public static List<Intersection> intersectTriangleTypes(Line line,
FloatBuffer vertices,
IntBuffer indices,
int triangleType)```
Compute the intersections of a line with a triangle collection.
Parameters:
`line` - the line to intersect.
`vertices` - the tri-fan vertices, in the order x, y, z, x, y, z, ...
`indices` - the indices forming the tri-fan.
`triangleType` - the type of triangle collection, either GL.GL_TRIANGLE_STRIP or GL.GL_TRIANGLE_FAN.
Returns:
the list of intersections with the line and the triangle fan, or null if there are no intersections.
• #### intersectTriFan

```public static List<Intersection> intersectTriFan(Line line,
FloatBuffer vertices,
IntBuffer indices)```
Compute the intersections of a line with a triangle fan.
Parameters:
`line` - the line to intersect.
`vertices` - the tri-fan vertices.
`indices` - the indices forming the tri-fan.
Returns:
the list of intersections with the line and the triangle fan, or null if there are no intersections.
Throws:
`IllegalArgumentException` - if the line, vertex buffer or index buffer is null.
• #### intersectTriFan

```public static List<Intersection> intersectTriFan(Line line,
Vec4[] vertices,
IntBuffer indices)```
Compute the intersections of a line with a triangle fan.
Parameters:
`line` - the line to intersect.
`vertices` - the tri-fan vertices.
`indices` - the indices forming the tri-fan.
Returns:
the list of intersections with the line and the triangle fan, or null if there are no intersections.
Throws:
`IllegalArgumentException` - if the line, vertex array or index buffer is null.
• #### intersectTriStrip

```public static List<Intersection> intersectTriStrip(Line line,
FloatBuffer vertices,
IntBuffer indices)```
Compute the intersections of a line with a triangle strip.
Parameters:
`line` - the line to intersect.
`vertices` - the tri-strip vertices.
`indices` - the indices forming the tri-strip.
Returns:
the list of intersections with the line and the tri-strip, or null if there are no intersections.
Throws:
`IllegalArgumentException` - if the line, vertex buffer or index buffer is null.
• #### intersectTriStrip

```public static List<Intersection> intersectTriStrip(Line line,
Vec4[] vertices,
IntBuffer indices)```
Compute the intersections of a line with a triangle strip.
Parameters:
`line` - the line to intersect.
`vertices` - the tri-strip vertices.
`indices` - the indices forming the tri-strip.
Returns:
the list of intersections with the line and the triangle strip, or null if there are no intersections.
Throws:
`IllegalArgumentException` - if the line, vertex array or index buffer is null.
• #### pointInTri

```protected static boolean pointInTri(double[] v0,
double[] u0,
double[] u1,
double[] u2,
int i0,
int i1)```
• #### toString

`public String toString()`
Overrides:
`toString` in class `Object`
• #### triangleEdgeTest

```protected static boolean triangleEdgeTest(double[] v0,
double[] v1,
double[] u0,
double[] u1,
double[] u2,
int i0,
int i1)```