Package com.irurueta.geometry
Class Triangle3D
java.lang.Object
com.irurueta.geometry.Triangle3D
- All Implemented Interfaces:
Serializable
This class defines a triangle in the 3D space.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleDefault threshold value.static final intConstant defining number of coordinatesstatic final doubleMinimum allowed threshold valuestatic final intConstant defining number of vertices on a triangleprivate Point3D1st vertex of this triangle.private Point3D2nd vertex of this triangle.private Point3D3rd vertex of this triangle. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleReturns area of the triangle formed by provided vertices.static doublearea(Triangle3D triangle) Returns area of provided triangle.booleanDetermines whether vertices of this triangle are considered to be co-linear.booleanareVerticesColinear(double threshold) Determines whether vertices of this triangle are considered to be co-linear up to certain threshold.voidComputes the center of this triangle and stores the result in provided point.static Point3DComputes the center of a triangle formed by provided vertices.static voidComputes the center of a triangle formed by provided vertices and stores the result in provided result point.static Point3Dcenter(Triangle3D t) Computes the center of provided triangle.static voidcenter(Triangle3D t, Point3D result) Computes the center of provided triangle and stores the result in provided result point.voidclosestPoint(Point3D point, Point3D result) Computes the point which is locus of this triangle closest to provided point and stores the result in provided result point.voidclosestPoint(Point3D point, Point3D result, double threshold) Computes the point which is locus of this triangle (up to a certain threshold) closest to provided point and stores the result in provided result point.private static doublegetAngleBetweenTriangles(double[] orientation1, double[] orientation2) Internal method to compute the angle between two triangles using the vectors containing the director vector of their corresponding planes (i.e. their orientations).static doublegetAngleBetweenTriangles(Triangle3D triangle1, Triangle3D triangle2) Returns the angle formed by the two provided triangles, assuming that each triangle forms a plane.doublegetArea()Returns area of this triangle.Returns center of this triangle, which is the result of averaging its vertices.getClosestPoint(Point3D point) Returns the point which is locus of this triangle closest to provided point.getClosestPoint(Point3D point, double threshold) Returns the point which is locus of this triangle (up to a certain threshold) closest to provided point.double[]Returns array containing orientation of this 3D triangle.double[]getOrientation(double threshold) Returns array containing orientation of this 3D triangle.doubleReturns perimeter of this triangle.doublegetShortestDistance(Point3D point) Computes the shortest distance from a given point to the boundaries of this triangle, considering its boundaries as lines with a finite length Distance is computed up to triangle boundary, no matter if point lies inside the triangle or not.Returns 1st vertex of this triangle.Returns 2nd vertex of this triangle.Returns 3rd vertex of this triangle.Returns vertices of this triangle as a list of points.booleanIndicates whether provided point lies inside this triangle or not.booleanIndicates whether provided point lies inside this triangle or not up to a certain threshold.static booleanIndicates whether provided point lies inside a triangle formed by provided vertices or not.static booleanIndicates whether provided point lies inside a triangle formed by provided vertices or not up to a certain threshold.static booleanisInside(Triangle3D triangle, Point3D point) Indicates whether provided point lies inside provided triangle or not To lie inside point must be on the same plane formed by provided triangle and within triangle boundaries.static booleanisInside(Triangle3D triangle, Point3D point, double threshold) Indicates whether provided point lies inside provided triangle or not up to a certain threshold.booleanReturns boolean indicating if provided point is locus of this triangle (i.e. lies within this triangle boundaries).booleanReturns boolean indicating if provided point is locus of this triangle (i.e. lies within this triangle boundaries) up to a certain threshold.voidorientation(double[] result) Computes orientation of this 3D triangle and stores the result in provided array.voidorientation(double[] result, double threshold) Computes orientation of this 3D triangle and stores the result in provided array.static double[]orientation(Point3D vertex1, Point3D vertex2, Point3D vertex3) Returns orientation of 3D triangle formed by provided vertices.static double[]orientation(Point3D vertex1, Point3D vertex2, Point3D vertex3, double threshold) Returns orientation of 3D triangle formed by provided vertices.static voidorientation(Point3D vertex1, Point3D vertex2, Point3D vertex3, double[] result) Computes orientation of 3D triangle formed by provided vertices and stores the result in provided array.static voidorientation(Point3D vertex1, Point3D vertex2, Point3D vertex3, double[] result, double threshold) Computes orientation of 3D triangle formed by provided vertices and stores the result in provided array.static double[]orientation(Triangle3D triangle) Returns orientation of provided 3D triangle.static double[]orientation(Triangle3D triangle, double threshold) Returns orientation of provided 3D triangle.static voidorientation(Triangle3D triangle, double[] result) Computes orientation of provided 3D triangle and stores the result in provided array.static voidorientation(Triangle3D triangle, double[] result, double threshold) Computes orientation of provided 3D triangle and stores the result in provided array.static doubleReturns perimeter of triangle formed by provided vertices.static doubleperimeter(Triangle3D triangle) Returns perimeter of provided triangle.voidsetVertex1(Point3D vertex1) Sets 1st vertex of this triangle.voidsetVertex2(Point3D vertex2) Sets 2nd vertex of this triangle.voidsetVertex3(Point3D vertex3) Sets 3rd vertex of this triangle.final voidsetVertices(Point3D vertex1, Point3D vertex2, Point3D vertex3) Sets all vertices of this triangle.static doubleshortestDistance(Point3D vertex1, Point3D vertex2, Point3D vertex3, Point3D point) Computes the shortest distance from a given point to the boundaries of a triangle formed by provided vertices, where those boundaries are considered to be lines with a finite length.static doubleshortestDistance(Triangle3D triangle, Point3D point) Computes the shortest distance from a given point to the boundaries of provided triangle, considering its boundaries as lines with a finite length.toPlane()Returns the plane formed by the vertices of this triangle.voidComputes the plane formed by the vertices of this triangle and stores the result into provided Plane instance.voidStores vertices of this triangle in provided list.
-
Field Details
-
DEFAULT_THRESHOLD
public static final double DEFAULT_THRESHOLDDefault threshold value. Thresholds are used to determine whether a point lies inside the triangle or not, or if its locus or not, etc.- See Also:
-
MIN_THRESHOLD
public static final double MIN_THRESHOLDMinimum allowed threshold value- See Also:
-
INHOM_COORDS
public static final int INHOM_COORDSConstant defining number of coordinates- See Also:
-
NUM_VERTICES
public static final int NUM_VERTICESConstant defining number of vertices on a triangle- See Also:
-
vertex1
1st vertex of this triangle. -
vertex2
2nd vertex of this triangle. -
vertex3
3rd vertex of this triangle.
-
-
Constructor Details
-
Triangle3D
Constructor.- Parameters:
vertex1- 1st vertex.vertex2- 2nd vertex.vertex3- 3rd vertex.- Throws:
NullPointerException- Raised if any of the vertices is null.
-
-
Method Details
-
getVertex1
Returns 1st vertex of this triangle.- Returns:
- 1st vertex.
-
setVertex1
Sets 1st vertex of this triangle.- Parameters:
vertex1- 1st vertex.- Throws:
NullPointerException- Raised if provided vertex is null.
-
getVertex2
Returns 2nd vertex of this triangle.- Returns:
- 2nd vertex.
-
setVertex2
Sets 2nd vertex of this triangle.- Parameters:
vertex2- 2nd vertex.- Throws:
NullPointerException- Raised if provided vertex is null.
-
getVertex3
Returns 3rd vertex of this triangle.- Returns:
- 3rd vertex.
-
setVertex3
Sets 3rd vertex of this triangle.- Parameters:
vertex3- 3rd vertex.- Throws:
NullPointerException- Raised if provided vertex is null.
-
getVertices
Returns vertices of this triangle as a list of points.- Returns:
- Vertices of this triangle.
-
vertices
Stores vertices of this triangle in provided list. Note that content of list will be cleared before storing this triangle's vertices.- Parameters:
result- list where vertices will be stored.
-
setVertices
Sets all vertices of this triangle.- Parameters:
vertex1- 1st vertex.vertex2- 2nd vertex.vertex3- 3rd vertex.- Throws:
NullPointerException- Raised if any of the vertices is null.
-
area
Returns area of provided triangle.- Parameters:
triangle- Triangle to be evaluated.- Returns:
- Area of triangle.
-
area
Returns area of the triangle formed by provided vertices.- Parameters:
vertex1- 1st vertex of a triangle.vertex2- 2nd vertex of a triangle.vertex3- 3rd vertex of a triangle.- Returns:
- Area of a triangle.
-
getArea
public double getArea()Returns area of this triangle.- Returns:
- Area of this triangle.
-
areVerticesColinear
public boolean areVerticesColinear()Determines whether vertices of this triangle are considered to be co-linear. Points are considered to be colinear when area of triangle is very small.- Returns:
- True if vertices are colinear, false otherwise.
-
areVerticesColinear
public boolean areVerticesColinear(double threshold) Determines whether vertices of this triangle are considered to be co-linear up to certain threshold. Points are considered to be colinear when are of triangle is very small.- Parameters:
threshold- Threshold to determine whether vertices are colinear. Vertices will be colinear when area of triangle is smaller than provided threshold.- Returns:
- True if vertices are colinear, false otherwise.
- Throws:
IllegalArgumentException- Raised if provided threshold is negative.
-
perimeter
Returns perimeter of provided triangle.- Parameters:
triangle- Perimeter of provided triangle.- Returns:
- Perimeter of provided triangle.
-
perimeter
Returns perimeter of triangle formed by provided vertices.- Parameters:
vertex1- 1st vertex of a triangle.vertex2- 2nd vertex of a triangle.vertex3- 3rd vertex of a triangle.- Returns:
- Perimeter of a triangle.
-
getPerimeter
public double getPerimeter()Returns perimeter of this triangle.- Returns:
- Perimeter of this triangle.
-
isInside
Indicates whether provided point lies inside this triangle or not. To lie inside point must be on the same plane formed by this triangle and within triangle boundaries.- Parameters:
point- Point to be checked.- Returns:
- True if point lies inside this triangle, false otherwise.
-
isInside
Indicates whether provided point lies inside this triangle or not up to a certain threshold. To lie inside point must be on the same plane formed by this triangle and within triangle boundaries up to a certain threshold.- Parameters:
point- Point to be checked.threshold- Threshold to determine whether point is inside this triangle, or not. This should usually be a small value.- Returns:
- True if point lies inside this triangle, false otherwise.
- Throws:
IllegalArgumentException- Raised if provided threshold is negative.
-
isInside
Indicates whether provided point lies inside provided triangle or not To lie inside point must be on the same plane formed by provided triangle and within triangle boundaries.- Parameters:
triangle- A triangle.point- Point to be checked.- Returns:
- True if point lies inside provided triangle, false otherwise.
-
isInside
Indicates whether provided point lies inside provided triangle or not up to a certain threshold. To lie inside point must be on the same plane formed by provided triangle and within triangle boundaries up to a certain threshold.- Parameters:
triangle- A triangle.point- Point to be checked.threshold- Threshold to determine whether point is inside this triangle, or not. This should usually be a small value.- Returns:
- True if point lies inside this triangle, false otherwise.
- Throws:
IllegalArgumentException- Raised if provided threshold is negative.
-
isInside
Indicates whether provided point lies inside a triangle formed by provided vertices or not. To lie inside point must be on the same plane formed by that triangle and within its boundaries.- Parameters:
vertex1- 1st vertex of a triangle.vertex2- 2nd vertex of a triangle.vertex3- 3rd vertex of a triangle.point- Point to be checked.- Returns:
- True if point lies inside triangle formed by provided vertices, false otherwise.
-
isInside
public static boolean isInside(Point3D vertex1, Point3D vertex2, Point3D vertex3, Point3D point, double threshold) Indicates whether provided point lies inside a triangle formed by provided vertices or not up to a certain threshold. To lie inside point must be on the same plane formed by that triangle and within its boundaries up to a certain threshold.- Parameters:
vertex1- 1st vertex of a triangle.vertex2- 2nd vertex of a triangle.vertex3- 3rd vertex of a triangle.point- Point to be checked.threshold- Threshold to determine whether point is inside the triangle formed by provided vertices or not. This should usually be a small value.- Returns:
- True if point lies inside triangle formed by provided vertices, false otherwise.
- Throws:
IllegalArgumentException- Raised if provided threshold is negative.
-
toPlane
Returns the plane formed by the vertices of this triangle. The difference between a plane and a 3D triangle is that a triangle has its boundaries defined, whereas a plane extends up to the infinity.- Returns:
- A plane.
- Throws:
ColinearPointsException- Raised if vertices of this triangle are co-linear (triangle has area equal or very close to 0.0).
-
toPlane
Computes the plane formed by the vertices of this triangle and stores the result into provided Plane instance. The difference between a plane and a 3D triangle is that a triangle has its boundaries defined, whereas a plane extends up to the infinity.- Parameters:
result- Instance where resulting plane will be stored.- Throws:
ColinearPointsException- Raised if vertices of this triangle are co-linear (triangle has area equal or very close to 0.0).
-
getCenter
Returns center of this triangle, which is the result of averaging its vertices.- Returns:
- Center of this triangle.
-
center
Computes the center of this triangle and stores the result in provided point. The center of this triangle is computed as the average of its vertices.- Parameters:
result- Point instance where center will be stored.
-
center
Computes the center of a triangle formed by provided vertices. The center is computed as the average of the three vertices.- Parameters:
vertex1- 1st vertex of a triangle.vertex2- 2nd vertex of a triangle.vertex3- 3rd vertex of a triangle.- Returns:
- Center of a triangle formed by provided vertices.
-
center
Computes the center of provided triangle. The center is computed as the average of the vertices of provided triangle.- Parameters:
t- A triangle.- Returns:
- Center of provided triangle.
-
center
Computes the center of a triangle formed by provided vertices and stores the result in provided result point. The center is computed as the average of provided vertices.- Parameters:
vertex1- 1st vertex of a triangle.vertex2- 2nd vertex of a triangle.vertex3- 3rd vertex of a triangle.result- Point instance where center will be stored.
-
center
Computes the center of provided triangle and stores the result in provided result point. The center is computed as the average of the vertices of provided triangle.- Parameters:
t- A triangle.result- Point instance where center will be stored.
-
getShortestDistance
Computes the shortest distance from a given point to the boundaries of this triangle, considering its boundaries as lines with a finite length Distance is computed up to triangle boundary, no matter if point lies inside the triangle or not.- Parameters:
point- Point to be checked.- Returns:
- Shortest distance to this triangle.
-
shortestDistance
Computes the shortest distance from a given point to the boundaries of provided triangle, considering its boundaries as lines with a finite length. Distance is computed up to triangle boundary, no matter if point lies inside the triangle or not.- Parameters:
triangle- A triangle.point- Point to be checked.- Returns:
- Shortest distance to this triangle.
-
shortestDistance
public static double shortestDistance(Point3D vertex1, Point3D vertex2, Point3D vertex3, Point3D point) Computes the shortest distance from a given point to the boundaries of a triangle formed by provided vertices, where those boundaries are considered to be lines with a finite length. Distance is computed up to triangle boundary, no matter if point lies inside the triangle or not.- Parameters:
vertex1- 1st vertex of a triangle.vertex2- 2nd vertex of a triangle.vertex3- 3rd vertex of a triangle.point- Point to be checked.- Returns:
- Shortest distance to the triangle formed by provided vertices.
-
getClosestPoint
Returns the point which is locus of this triangle closest to provided point.- Parameters:
point- Point to be checked.- Returns:
- Closest point laying in this triangle boundaries.
-
getClosestPoint
Returns the point which is locus of this triangle (up to a certain threshold) closest to provided point.- Parameters:
point- Point to be checked.threshold- Threshold to determine when a point is locus of this triangle or not.- Returns:
- Closest point laying in this triangle boundaries.
- Throws:
IllegalArgumentException- Raised if provided threshold is negative.
-
closestPoint
Computes the point which is locus of this triangle closest to provided point and stores the result in provided result point.- Parameters:
point- Point to be checked.result- Point where result will be stored.
-
closestPoint
Computes the point which is locus of this triangle (up to a certain threshold) closest to provided point and stores the result in provided result point.- Parameters:
point- Point to be checked.result- Point where result will be stored.threshold- Threshold to determine when a point is locus of this triangle or not.- Throws:
IllegalArgumentException- Raised if provided threshold is negative.
-
isLocus
Returns boolean indicating if provided point is locus of this triangle (i.e. lies within this triangle boundaries) up to a certain threshold.- Parameters:
point- Point to be checked.threshold- Threshold to determine if point is locus or not. This should usually be a small value.- Returns:
- True if provided point is locus, false otherwise.
- Throws:
IllegalArgumentException- Raised if provided threshold is negative.
-
isLocus
Returns boolean indicating if provided point is locus of this triangle (i.e. lies within this triangle boundaries).- Parameters:
point- Point to be checked.- Returns:
- True if provided point is locus, false otherwise.
-
getOrientation
Returns array containing orientation of this 3D triangle.- Returns:
- Array containing orientation of this 3D triangle.
- Throws:
CoincidentPointsException- Raised if vertices of this triangle are too close to each other.
-
getOrientation
Returns array containing orientation of this 3D triangle.- Parameters:
threshold- Threshold to determine whether vertices of this triangle are coincident or not.- Returns:
- Array containing orientation of this 3D triangle.
- Throws:
IllegalArgumentException- Raised if provided threshold is negative.CoincidentPointsException- Raised if vertices of this triangle are too close to each other.
-
orientation
Computes orientation of this 3D triangle and stores the result in provided array.- Parameters:
result- Array where orientation is stored.- Throws:
IllegalArgumentException- Raised if provided array does not have length 3.CoincidentPointsException- Raised if vertices of this triangle are too close to each other.
-
orientation
Computes orientation of this 3D triangle and stores the result in provided array.- Parameters:
result- Array where orientation is stored.threshold- Threshold to determine whether vertices of this triangle are coincident or not.- Throws:
IllegalArgumentException- Raised if provided threshold is negative or if provided array does not have length 3.CoincidentPointsException- Raised if vertices of this triangle are too close to each other.
-
orientation
Returns orientation of provided 3D triangle.- Parameters:
triangle- A triangle.- Returns:
- Array containing orientation of provided 3D triangle.
- Throws:
CoincidentPointsException- Raised if vertices of provided triangle are too close to each other.
-
orientation
public static double[] orientation(Triangle3D triangle, double threshold) throws CoincidentPointsException Returns orientation of provided 3D triangle.- Parameters:
triangle- A triangle.threshold- Threshold to determine whether vertices of provided triangle are coincident or not.- Returns:
- Array containing orientation of provided 3D triangle.
- Throws:
IllegalArgumentException- Raised if provided threshold is negative.CoincidentPointsException- Raised if vertices of this triangle are too close to each other.
-
orientation
public static void orientation(Triangle3D triangle, double[] result) throws CoincidentPointsException Computes orientation of provided 3D triangle and stores the result in provided array.- Parameters:
triangle- A triangle.result- Array where orientation is stored.- Throws:
IllegalArgumentException- Raised if provided array does not have length 3.CoincidentPointsException- Raised if vertices of provided triangle are too close to each other.
-
orientation
public static void orientation(Triangle3D triangle, double[] result, double threshold) throws CoincidentPointsException Computes orientation of provided 3D triangle and stores the result in provided array.- Parameters:
triangle- A triangle.result- Array where orientation is stored.threshold- Threshold to determine whether vertices of provided triangle are coincident or not.- Throws:
IllegalArgumentException- Raised if provided threshold is negative or if array does not have length 3.CoincidentPointsException- Raised if vertices of provided triangle are too close to each other.
-
orientation
public static double[] orientation(Point3D vertex1, Point3D vertex2, Point3D vertex3) throws CoincidentPointsException Returns orientation of 3D triangle formed by provided vertices.- Parameters:
vertex1- 1st vertex.vertex2- 2nd vertex.vertex3- 3rd vertex.- Returns:
- Array containing triangle orientation.
- Throws:
CoincidentPointsException- Raised if provided vertices are too close to each other.
-
orientation
public static double[] orientation(Point3D vertex1, Point3D vertex2, Point3D vertex3, double threshold) throws CoincidentPointsException Returns orientation of 3D triangle formed by provided vertices.- Parameters:
vertex1- 1st vertex.vertex2- 2nd vertex.vertex3- 3rd vertex.threshold- Threshold to determine whether provided vertices are coincident or not.- Returns:
- Array containing triangle orientation.
- Throws:
IllegalArgumentException- Raised if provided threshold is negative.CoincidentPointsException- Raised if provided vertices are too close to each other.
-
orientation
public static void orientation(Point3D vertex1, Point3D vertex2, Point3D vertex3, double[] result) throws CoincidentPointsException Computes orientation of 3D triangle formed by provided vertices and stores the result in provided array.- Parameters:
vertex1- 1st vertex.vertex2- 2nd vertex.vertex3- 3rd vertex.result- Array where triangle orientation is stored.- Throws:
IllegalArgumentException- Raised if provided array does not have length 3.CoincidentPointsException- Raised if provided vertices are too close to each other.
-
orientation
public static void orientation(Point3D vertex1, Point3D vertex2, Point3D vertex3, double[] result, double threshold) throws CoincidentPointsException Computes orientation of 3D triangle formed by provided vertices and stores the result in provided array.- Parameters:
vertex1- 1st vertex.vertex2- 2nd vertex.vertex3- 3rd vertex.result- Array where triangle orientation is stored.threshold- Threshold to determine whether provided vertices are coincident or not.- Throws:
IllegalArgumentException- Raised if threshold is negative or if provided array does not have length 3.CoincidentPointsException- Raised if provided vertices are too close to each other.
-
getAngleBetweenTriangles
public static double getAngleBetweenTriangles(Triangle3D triangle1, Triangle3D triangle2) throws CoincidentPointsException Returns the angle formed by the two provided triangles, assuming that each triangle forms a plane.- Parameters:
triangle1- 1st triangle.triangle2- 2nd triangle.- Returns:
- Angle formed by the two provided triangles expressed in radians.
- Throws:
CoincidentPointsException- Raised if vertices in a triangle are too close. This usually indicates numerical instability or triangle degeneracy.
-
getAngleBetweenTriangles
private static double getAngleBetweenTriangles(double[] orientation1, double[] orientation2) Internal method to compute the angle between two triangles using the vectors containing the director vector of their corresponding planes (i.e. their orientations).- Parameters:
orientation1- Orientation of 1st triangle.orientation2- Orientation of 2nd triangle.- Returns:
- Angle formed by the two triangles expressed in radians.
- Throws:
IllegalArgumentException- Raised if provided orientation arrays don't have length 3.
-