Package gov.nasa.worldwind.geom
Class Triangle
- java.lang.Object
-
- gov.nasa.worldwind.geom.Triangle
-
public class Triangle extends java.lang.ObjectProvides operations on triangles.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classTriangle.TriangleIntersectionDefines a line segment representing the intersection of a line with and in the plane of a triangle.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static Triangle.TriangleIntersectioncompute_intervals_isectline(Vec4[] v, double vv0, double vv1, double vv2, double d0, double d1, double d2, double d0d1, double d0d2)booleancontains(Vec4 p)Indicates whether a specified point is on the triangle.protected static booleancoplanarTriangles(Vec4 n, Vec4[] v, Vec4[] u)protected static booleanedgeEdgeTest(double[] v0, double[] u0, double[] u1, int i0, int i1, double ax, double ay)static voidexpandTriangleFan(java.util.List<java.lang.Integer> indices, java.nio.FloatBuffer inBuf, java.nio.FloatBuffer outBuf)Expands a buffer of indexed triangle fan vertices to a buffer of non-indexed general-triangle vertices.static voidexpandTriangleFan(java.util.List<java.lang.Integer> indices, java.nio.IntBuffer outBuf)static voidexpandTriangles(java.util.List<java.lang.Integer> indices, java.nio.FloatBuffer inBuf, java.nio.FloatBuffer outBuf)Expands a buffer of indexed triangle vertices to a buffer of non-indexed triangle vertices.static voidexpandTriangles(java.util.List<java.lang.Integer> indices, java.nio.IntBuffer outBuf)static voidexpandTriangleStrip(java.util.List<java.lang.Integer> indices, java.nio.FloatBuffer inBuf, java.nio.FloatBuffer outBuf)Expands a buffer of indexed triangle strip vertices to a buffer of non-indexed general-triangle vertices.static voidexpandTriangleStrip(java.util.List<java.lang.Integer> indices, java.nio.IntBuffer outBuf)Vec4getA()Returns the first vertex.Vec4getB()Returns the second vertex.Vec4getC()Returns the third vertex.Vec4intersect(Line line)Determine the intersection of the triangle with a specified line.static Intersectionintersect(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 Intersectionintersect(Line line, Vec4 a, Vec4 b, Vec4 c)Determines the intersection of a specified line with a specified triangle.protected static Triangle.TriangleIntersectionintersect(Vec4 v0, Vec4 v1, Vec4 v2, double vv0, double vv1, double vv2, double d0, double d1, double d2)static java.util.List<Intersection>intersectTriangles(Line line, java.nio.FloatBuffer vertices)Compute the intersections of a line with a collection of triangles.static java.util.List<Intersection>intersectTriangles(Line line, java.nio.FloatBuffer vertices, java.nio.IntBuffer indices)Compute the intersections of a line with a collection of triangles.static intintersectTriangles(Vec4[] v, Vec4[] u, Vec4[] intersectionVertices)Intersects two triangles and returns their intersection vertices.static java.util.List<Intersection>intersectTriangleTypes(Line line, java.nio.FloatBuffer vertices, java.nio.IntBuffer indices, int triangleType)Compute the intersections of a line with a triangle collection.static java.util.List<Intersection>intersectTriFan(Line line, Vec4[] vertices, java.nio.IntBuffer indices)Compute the intersections of a line with a triangle fan.static java.util.List<Intersection>intersectTriFan(Line line, java.nio.FloatBuffer vertices, java.nio.IntBuffer indices)Compute the intersections of a line with a triangle fan.static java.util.List<Intersection>intersectTriStrip(Line line, Vec4[] vertices, java.nio.IntBuffer indices)Compute the intersections of a line with a triangle strip.static java.util.List<Intersection>intersectTriStrip(Line line, java.nio.FloatBuffer vertices, java.nio.IntBuffer indices)Compute the intersections of a line with a triangle strip.protected static booleanpointInTri(double[] v0, double[] u0, double[] u1, double[] u2, int i0, int i1)java.lang.StringtoString()protected static booleantriangleEdgeTest(double[] v0, double[] v1, double[] u0, double[] u1, double[] u2, int i0, int i1)
-
-
-
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:
java.lang.IllegalArgumentException- if any vertex is null.
-
-
Method Detail
-
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.
-
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.
-
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:
java.lang.IllegalArgumentException- if the line is 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:
java.lang.IllegalArgumentException- if the line or any of the triangle vertices 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.
-
intersectTriStrip
public static java.util.List<Intersection> intersectTriStrip(Line line, java.nio.FloatBuffer vertices, java.nio.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:
java.lang.IllegalArgumentException- if the line, vertex buffer or index buffer is null.
-
intersectTriStrip
public static java.util.List<Intersection> intersectTriStrip(Line line, Vec4[] vertices, java.nio.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:
java.lang.IllegalArgumentException- if the line, vertex array or index buffer is null.
-
intersectTriFan
public static java.util.List<Intersection> intersectTriFan(Line line, java.nio.FloatBuffer vertices, java.nio.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:
java.lang.IllegalArgumentException- if the line, vertex buffer or index buffer is null.
-
intersectTriFan
public static java.util.List<Intersection> intersectTriFan(Line line, Vec4[] vertices, java.nio.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:
java.lang.IllegalArgumentException- if the line, vertex array or index buffer is null.
-
intersectTriangles
public static java.util.List<Intersection> intersectTriangles(Line line, java.nio.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:
java.lang.IllegalArgumentException- if the line or vertex buffer is null.
-
intersectTriangles
public static java.util.List<Intersection> intersectTriangles(Line line, java.nio.FloatBuffer vertices, java.nio.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:
java.lang.IllegalArgumentException- if the line, vertex buffer or index buffer is null.
-
intersectTriangleTypes
public static java.util.List<Intersection> intersectTriangleTypes(Line line, java.nio.FloatBuffer vertices, java.nio.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.
-
expandTriangles
public static void expandTriangles(java.util.List<java.lang.Integer> indices, java.nio.FloatBuffer inBuf, java.nio.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:
java.lang.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(java.util.List<java.lang.Integer> indices, java.nio.FloatBuffer inBuf, java.nio.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:
java.lang.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(java.util.List<java.lang.Integer> indices, java.nio.FloatBuffer inBuf, java.nio.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:
java.lang.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(java.util.List<java.lang.Integer> indices, java.nio.IntBuffer outBuf)
-
expandTriangleFan
public static void expandTriangleFan(java.util.List<java.lang.Integer> indices, java.nio.IntBuffer outBuf)
-
expandTriangleStrip
public static void expandTriangleStrip(java.util.List<java.lang.Integer> indices, java.nio.IntBuffer outBuf)
-
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.
-
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)
-
intersect
protected static Triangle.TriangleIntersection intersect(Vec4 v0, Vec4 v1, Vec4 v2, double vv0, double vv1, double vv2, double d0, double d1, double d2)
-
triangleEdgeTest
protected static boolean triangleEdgeTest(double[] v0, double[] v1, double[] u0, double[] u1, double[] u2, int i0, int i1)
-
edgeEdgeTest
protected static boolean edgeEdgeTest(double[] v0, double[] u0, double[] u1, int i0, int i1, double ax, double ay)
-
pointInTri
protected static boolean pointInTri(double[] v0, double[] u0, double[] u1, double[] u2, int i0, int i1)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-