Package com.irurueta.geometry
Class Polygon3D
java.lang.Object
com.irurueta.geometry.Polygon3D
- All Implemented Interfaces:
Serializable
This class defines a polygon in 3D space.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleDefault threshold value.static final TriangulatorMethodDefault method for triangulation.static final intConstant defining inhomogeneous coordinates.static final doubleMinimum allowed threshold value.static final intMinimum number of vertices that a polygon is allowed to have.private List<Triangle3D> List containing triangles found after triangulating this polygon.private booleanBoolean indicating whether polygon has already been triangulated.private TriangulatorMethodMethod to do triangulation.List containing vertices of this polygon. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidComputes the center of this polygon.voidclosestPoint(Point3D point, Point3D result) Computes the closes point to provided point that is locus of this polygon (i.e. lies on a border of this polygon).private static doublegetAngleBetweenOrientations(double[] orientation1, double[] orientation2) Internal method to compute polygon orientation from their respective orientation vectors.static doublegetAngleBetweenPolygons(Polygon3D polygon1, Polygon3D polygon2) Returns the angle between two polygons, assuming that all vertices of each polygon lie on a given plane.static doublegetAngleBetweenPolygons(Polygon3D polygon1, Polygon3D polygon2, double threshold) Returns the angle between two polygons, assuming that all vertices of each polygon lie on a given plane.static doublegetAngleBetweenPolygons(List<Point3D> vertices1, List<Point3D> vertices2) Returns the angle between two polygons formed each of them by the corresponding list of provided vertices and assuming that all vertices of each polygon lie on a given plane.static doublegetAngleBetweenPolygons(List<Point3D> vertices1, List<Point3D> vertices2, double threshold) Returns the angle between two polygons formed each of them by the corresponding list of provided vertices and assuming that all vertices of each polygon lie on a given plane.doublegetArea()Returns signed area of this polygon.Returns the center of this polygon.getClosestPoint(Point3D point) Returns the closest point to provided point that is locus of this polygon (i.e. lies on a border of this polygon).double[]Returns the average orientation of provided 3D polygon as an array containing the vector coordinates of the orientation.double[]getOrientation(double threshold) Returns the average orientation of provided 3D polygon as an array containing the vector coordinates of the orientation.doubleReturns perimeter of this polygon.doublegetShortestDistance(Point3D point) Returns the shortest distance from provided point to a border of this polygon.Returns a list of triangles forming this polygon.Returns triangulator method.Returns the list of vertices forming this polygon.booleanDetermines if provided point lies within the region defined by this polygon.booleanDetermines if provided point lies within the region defined by this polygon.booleanDetermines whether provided point is locus of the borders defined by the vertices of this polygon.booleanDetermines whether provided point is locus of the borders defined by the vertices of this polygon.booleanDetermines whether this polygon has already been triangulated.voidorientation(double[] result) Computes the average orientation of provided 3D polygon as an array containing the vector coordinates of the orientation.voidorientation(double[] result, double threshold) Computes the average orientation of this polygon as an array containing the vector coordinates of the orientation.static double[]orientation(Polygon3D polygon) Returns the average orientation of provided 3D polygon as an array containing the vector coordinates of the orientation.static double[]orientation(Polygon3D polygon, double threshold) Returns the average orientation of provided 3D polygon as an array containing the vector coordinates of the orientation.static voidorientation(Polygon3D polygon, double[] result) Computes the average orientation of provided 3D polygon as an array containing the vector coordinates of the orientation.static voidorientation(Polygon3D polygon, double[] result, double threshold) Computes the average orientation of provided 3D polygon as an array containing the vector coordinates of the orientation.static double[]orientation(List<Point3D> vertices) Returns the average orientation of a 3D polygon as an array containing the vector coordinates of the orientation.static double[]orientation(List<Point3D> vertices, double threshold) Returns the average orientation of a 3D polygon as an array containing the vector coordinates of the orientation.static voidorientation(List<Point3D> vertices, double[] result) Computes the average orientation of a 3D polygon as an array containing the vector coordinates of the orientation.static voidorientation(List<Point3D> vertices, double[] result, double threshold) Computes the average orientation of a 3D polygon as an array containing the vector coordinates of the orientation.voidsetTriangulatorMethod(TriangulatorMethod triangulatorMethod) Sets triangulator method.final voidsetVertices(List<Point3D> vertices) Sets list of vertices forming this polygon.voidTriangulates this polygon using this polygon's triangulator method.
-
Field Details
-
DEFAULT_THRESHOLD
public static final double DEFAULT_THRESHOLDDefault threshold value. Thresholds are used to determine whether a point lies inside the polygon or not, or if it's locus or not, etc.- See Also:
-
MIN_THRESHOLD
public static final double MIN_THRESHOLDMinimum allowed threshold value.- See Also:
-
MIN_VERTICES
public static final int MIN_VERTICESMinimum number of vertices that a polygon is allowed to have.- See Also:
-
INHOM_COORDS
public static final int INHOM_COORDSConstant defining inhomogeneous coordinates.- See Also:
-
DEFAULT_TRIANGULATOR_METHOD
Default method for triangulation. -
vertices
List containing vertices of this polygon. Each vertex is a 3D point. -
triangulated
private boolean triangulatedBoolean indicating whether polygon has already been triangulated. -
triangles
List containing triangles found after triangulating this polygon. Initially this list will be null until triangulation is done. -
triangulatorMethod
Method to do triangulation.
-
-
Constructor Details
-
Polygon3D
Constructor.- Parameters:
vertices- List of vertices forming this polygon.- Throws:
NotEnoughVerticesException- Raised if list does not contain enough vertices.- See Also:
-
-
Method Details
-
getTriangulatorMethod
Returns triangulator method. Triangulator method determines the way a polygon is divided into triangles. If none has been provided DEFAULT_TRIANGULATOR_METHOD will be returned.- Returns:
- Triangulator method.
-
setTriangulatorMethod
Sets triangulator method. A triangulator method determines the way a polygon is divided into triangles.- Parameters:
triangulatorMethod- A triangulator method.
-
getVertices
Returns the list of vertices forming this polygon.- Returns:
- List of vertices.
-
setVertices
Sets list of vertices forming this polygon.- Parameters:
vertices- List of vertices.- Throws:
NotEnoughVerticesException- Raised if provided list does not have enough vertices.- See Also:
-
isTriangulated
public boolean isTriangulated()Determines whether this polygon has already been triangulated. A polygon will only need to be triangulated once, unless the list of vertices is reset.- Returns:
- True if polygon has already been triangulated, false otherwise.
-
getTriangles
Returns a list of triangles forming this polygon. This method checks whether this polygon has already been triangulated, if not, it performs triangulation first.- Returns:
- A list of triangles forming this polygon.
- Throws:
TriangulatorException- Raised if triangulation was needed and failed.
-
getArea
public double getArea()Returns signed area of this polygon. The sign of the area determines whether vertices of the polygon are provided in clockwise (negative sign) or clockwise (positive sign) order.- Returns:
- Signed area of this polygon.
-
getPerimeter
public double getPerimeter()Returns perimeter of this polygon. The perimeter is computed as the sum of the distances between consecutive pairs of vertices.- Returns:
- Perimeter of this polygon.
-
isInside
Determines if provided point lies within the region defined by this polygon. Notice that this method is only ensured to work for polygons having no holes or crossing borders. It will safely work on any other polygon, no matter if it is regular, non-regular, convex or concave.- Parameters:
point- Point to be checked.- Returns:
- True if point lies within the area defined by this polygon, false otherwise.
- Throws:
TriangulatorException- Raised if triangulation was required but failed.
-
isInside
Determines if provided point lies within the region defined by this polygon. Notice that this method is only ensured to work for polygons having no holes or crossing borders. It will safely work on any other polygon, no matter if it is regular, non-regular, convex or concave.- Parameters:
point- Point to be checked.threshold- Threshold to determine whether point lies inside this polygon. Usually this value should be small.- Returns:
- True if point lies within the area defined by this polygon, false otherwise.
- Throws:
IllegalArgumentException- Raised if provided threshold is negative.TriangulatorException- Raised if triangulation was required but failed.
-
getCenter
Returns the center of this polygon. The center is the average point among all the vertices of this polygon. The center is not ensure to lie within the area formed by this polygon.- Returns:
- Center of this polygon.
-
center
Computes the center of this polygon. The center is the average point among all the vertices of this polygon. The center is not ensured to lie within the area formed by this polygon.- Parameters:
result- Instance where the computed center will be stored.
-
isLocus
Determines whether provided point is locus of the borders defined by the vertices of this polygon. A point will be locus if it lies in the line defined by two consecutive vertices up to a certain threshold of error.- Parameters:
point- Point to be checked.threshold- Threshold of allowed error. This should usually be a small value.- Returns:
- True if provided point lies in a border of this polygon, false otherwise.
- Throws:
IllegalArgumentException- Raised if provided threshold is negative.
-
isLocus
Determines whether provided point is locus of the borders defined by the vertices of this polygon. A point will be locus if it lies in the line defined by two consecutive vertices.- Parameters:
point- Point to be checked.- Returns:
- True if provided point lies in a border of this polygon, false otherwise.
-
getShortestDistance
Returns the shortest distance from provided point to a border of this polygon. Note that borders are segments defined by consecutive vertices- Parameters:
point- Point to be checked.- Returns:
- Shortest distance from provided point to this polygon.
- Throws:
CoincidentPointsException- Raised if points in a polygon are too close. This usually indicates numerical instability or polygon degeneracy.
-
getClosestPoint
Returns the closest point to provided point that is locus of this polygon (i.e. lies on a border of this polygon).- Parameters:
point- Point to be checked.- Returns:
- Closest point being locus of this polygon.
- Throws:
CoincidentPointsException- Raised if points in a polygon are too close. This usually indicates numerical instability or polygon degeneracy.
-
closestPoint
Computes the closes point to provided point that is locus of this polygon (i.e. lies on a border of this polygon).- Parameters:
point- Point to be checked.result- Instance where the closest point will be stored.- Throws:
CoincidentPointsException- Raised if points in a polygon are too close. This usually indicates numerical instability or polygon degeneracy.
-
triangulate
Triangulates this polygon using this polygon's triangulator method. A polygon only will be triangulated once when required or this method is called. This method will make no action if a polygon is already triangulated unless it's vertices are reset.- Throws:
TriangulatorException- Raised if triangulation failed.- See Also:
-
orientation
public static void orientation(List<Point3D> vertices, double[] result, double threshold) throws CoincidentPointsException Computes the average orientation of a 3D polygon as an array containing the vector coordinates of the orientation. Notice that if all the vertices of the polygon lie in the same plane, then the estimated orientation will be exact, otherwise an average orientation will be estimated. Estimated orientation will be normalized (the norm of the estimated vector will be 1).- Parameters:
vertices- List of vertices forming a polygon in 3D.result- Array where the estimated orientation will be stored.threshold- Threshold to determine whether the orientation can be estimated or not. Because the estimated orientation needs to be normalized, it will only be possible to do so when norm has a reasonable value. If estimated norm happens to be smaller than provided value, then it will be assumed that polygon contains a degeneracy or that a consecutive pair of vertices are coincident.- Throws:
IllegalArgumentException- Raised if provided result array does not have length 3, or if the list of provided vertices does not contain at least three vertices, or if provided threshold is negative.CoincidentPointsException- Raised usually when it is determined that consecutive vertices of the polygon are too close (i.e. coincident) or when there are polygon degeneracies or numerical instabilities.
-
orientation
public static void orientation(List<Point3D> vertices, double[] result) throws CoincidentPointsException Computes the average orientation of a 3D polygon as an array containing the vector coordinates of the orientation. Notice that if all the vertices of the polygon lie in the same plane, then the estimated orientation will be exact, otherwise an average orientation will be estimated. Estimated orientation will be normalized (the norm of the estimated vector will be 1).- Parameters:
vertices- List of vertices forming a polygon in 3D.result- Array where the estimated orientation will be stored.- Throws:
IllegalArgumentException- Raised if provided result array does not have length 3, or if the list of provided vertices does not contain at least three vertices.CoincidentPointsException- Raised usually when it is determined that consecutive vertices of the polygon are too close (i.e. coincident) or when there are polygon degeneracies or numerical instabilities.
-
orientation
public static double[] orientation(List<Point3D> vertices, double threshold) throws CoincidentPointsException Returns the average orientation of a 3D polygon as an array containing the vector coordinates of the orientation. Notice that if all the vertices of the polygon lie in the same plane, then the estimated orientation will be exact, otherwise an average orientation will be estimated. Estimated orientation will be normalized (the norm of the estimated vector will be 1).- Parameters:
vertices- List of vertices forming a polygon in 3D.threshold- Threshold to determine whether the orientation can be estimated or not. Because the estimated orientation needs to be normalized, it will only be possible to do so when norm has a reasonable value. If estimated norm happens to be smaller than provided value, then it will be assumed that polygon contains a degeneracy or that a consecutive pair of vertices are coincident.- Returns:
- Array containing estimated orientation.
- Throws:
IllegalArgumentException- Raised if the list of provided vertices does not contain at least three vertices, or if provided threshold is negative.CoincidentPointsException- Raised usually when it is determined that consecutive vertices of the polygon are too close (i.e. coincident) or when there are polygon degeneracies or numerical instabilities.
-
orientation
Returns the average orientation of a 3D polygon as an array containing the vector coordinates of the orientation. Notice that if all the vertices of the polygon lie in the same plane, then the estimated orientation will be exact, otherwise an average orientation will be estimated. Estimated orientation will be normalized (the norm of the estimated vector will be 1).- Parameters:
vertices- List of vertices forming a polygon in 3D- Returns:
- Array containing estimated orientation.
- Throws:
IllegalArgumentException- Raised if the list of provided vertices does not contain at least three vertices.CoincidentPointsException- Raised usually when it is determined that consecutive vertices of the polygon are too close (i.e. coincident) or when there are polygon degeneracies or numerical instabilities.
-
orientation
public static void orientation(Polygon3D polygon, double[] result, double threshold) throws CoincidentPointsException Computes the average orientation of provided 3D polygon as an array containing the vector coordinates of the orientation. Notice that if all the vertices of the polygon lie in the same plane, then the estimated orientation will be exact, otherwise an average orientation will be estimated. Estimated orientation will be normalized (the norm of the estimated vector will be 1).- Parameters:
polygon- A polygon in 3D.result- Array where the estimated orientation will be stored.threshold- Threshold to determine whether the orientation can be estimated or not. Because the estimated orientation needs to be normalized, it will only be possible to do so when norm has a reasonable value. If estimated norm happens to be smaller than provided value, then it will be assumed that polygon contains a degeneracy or that a consecutive pair of vertices are coincident.- Throws:
IllegalArgumentException- Raised if provided result array does not have length 3 or if provided threshold is negative.CoincidentPointsException- Raised usually when it is determined that consecutive vertices of the polygon are too close (i.e. coincident) or when there are polygon degeneracies or numerical instabilities.
-
orientation
Computes the average orientation of provided 3D polygon as an array containing the vector coordinates of the orientation. Notice that if all the vertices of the polygon lie in the same plane, then the estimated orientation will be exact, otherwise an average orientation will be estimated. Estimated orientation will be normalized (the norm of the estimated vector will be 1).- Parameters:
polygon- A polygon in 3D.result- Array where the estimated orientation will be stored.- Throws:
IllegalArgumentException- Raised if provided result array does not have length 3.CoincidentPointsException- Raised usually when it is determined that consecutive vertices of the polygon are too close (i.e. coincident) or when there are polygon degeneracies or numerical instabilities.
-
orientation
public static double[] orientation(Polygon3D polygon, double threshold) throws CoincidentPointsException Returns the average orientation of provided 3D polygon as an array containing the vector coordinates of the orientation. Notice that if all the vertices of the polygon lie in the same plane, then the estimated orientation will be exact, otherwise an average orientation will be estimated. Estimated orientation will be normalized (the norm of the estimated vector will be 1).- Parameters:
polygon- A polygon in 3D.threshold- Threshold to determine whether the orientation can be estimated or not. Because the estimated orientation needs to be normalized, it will only be possible to do so when norm has a reasonable value. If estimated norm happens to be smaller than provided value, then it will be assumed that polygon contains a degeneracy or that a consecutive pair of vertices are coincident.- Returns:
- Array containing estimated orientation.
- Throws:
IllegalArgumentException- Raised if provided threshold is negative.CoincidentPointsException- Raised usually when it is determined that consecutive vertices of the polygon are too close (i.e. coincident) or when there are polygon degeneracies or numerical instabilities.
-
orientation
Returns the average orientation of provided 3D polygon as an array containing the vector coordinates of the orientation. Notice that if all the vertices of the polygon lie in the same plane, then the estimated orientation will be exact, otherwise an average orientation will be estimated. Estimated orientation will be normalized (the norm of the estimated vector will be 1).- Parameters:
polygon- A polygon in 3D.- Returns:
- Array containing estimated orientation.
- Throws:
CoincidentPointsException- Raised usually when it is determined that consecutive vertices of the polygon are too close (i.e. coincident) or when there are polygon degeneracies or numerical instabilities.
-
orientation
Computes the average orientation of this polygon as an array containing the vector coordinates of the orientation. Notice that if all the vertices of the polygon lie in the same plane, then the estimated orientation will be exact, otherwise an average orientation will be estimated. Estimated orientation will be normalized (the norm of the estimated vector will be 1).- Parameters:
result- Array where the estimated orientation will be stored.threshold- Threshold to determine whether the orientation can be estimated or not. Because the estimated orientation needs to be normalized, it will only be possible to do so when norm has a reasonable value. If estimated norm happens to be smaller than provided value, then it will be assumed that polygon contains a degeneracy or that a consecutive pair of vertices are coincident.- Throws:
IllegalArgumentException- Raised if provided result array does not have length 3 or if provided threshold is negative.CoincidentPointsException- Raised usually when it is determined that consecutive vertices of the polygon are too close (i.e. coincident) or when there are polygon degeneracies or numerical instabilities.
-
orientation
Computes the average orientation of provided 3D polygon as an array containing the vector coordinates of the orientation. Notice that if all the vertices of the polygon lie in the same plane, then the estimated orientation will be exact, otherwise an average orientation will be estimated. Estimated orientation will be normalized (the norm of the estimated vector will be 1).- Parameters:
result- Array where the estimated orientation will be stored.- Throws:
IllegalArgumentException- Raised if provided result array does not have length 3.CoincidentPointsException- Raised usually when it is determined that consecutive vertices of the polygon are too close (i.e. coincident) or when there are polygon degeneracies or numerical instabilities.
-
getOrientation
Returns the average orientation of provided 3D polygon as an array containing the vector coordinates of the orientation. Notice that if all the vertices of the polygon lie in the same plane, then the estimated orientation will be exact, otherwise an average orientation will be estimated. Estimated orientation will be normalized (the norm of the estimated vector will be 1).- Parameters:
threshold- Threshold to determine whether the orientation can be estimated or not. Because the estimated orientation needs to be normalized, it will only be possible to do so when norm has a reasonable value. If estimated norm happens to be smaller than provided value, then it will be assumed that polygon contains a degeneracy or that a consecutive pair of vertices are coincident.- Returns:
- Array containing estimated orientation.
- Throws:
IllegalArgumentException- Raised if provided threshold is negative.CoincidentPointsException- Raised usually when it is determined that consecutive vertices of the polygon are too close (i.e. coincident) or when there are polygon degeneracies or numerical instabilities.
-
getOrientation
Returns the average orientation of provided 3D polygon as an array containing the vector coordinates of the orientation. Notice that if all the vertices of the polygon lie in the same plane, then the estimated orientation will be exact, otherwise an average orientation will be estimated. Estimated orientation will be normalized (the norm of the estimated vector will be 1).- Returns:
- Array containing estimated orientation.
- Throws:
CoincidentPointsException- Raised usually when it is determined that consecutive vertices of the polygon are too close (i.e. coincident) or when there are polygon degeneracies or numerical instabilities.
-
getAngleBetweenPolygons
public static double getAngleBetweenPolygons(Polygon3D polygon1, Polygon3D polygon2, double threshold) throws CoincidentPointsException Returns the angle between two polygons, assuming that all vertices of each polygon lie on a given plane. Hence, this is equivalent to estimating the angle between the planes formed by two polygons. The angle between two polygons is estimated by first estimating their orientation.- Parameters:
polygon1- 1st polygon.polygon2- 2nd polygon.threshold- Threshold to determine when polygon orientation can be estimated.- Returns:
- Angle between two polygons in radians.
- Throws:
IllegalArgumentException- Raised if provided threshold is negative.CoincidentPointsException- Raised usually when it is determined that consecutive vertices of the polygon are too close (i.e. coincident) or when there are polygon degeneracies or numerical instabilities.- See Also:
-
getAngleBetweenPolygons
public static double getAngleBetweenPolygons(Polygon3D polygon1, Polygon3D polygon2) throws CoincidentPointsException Returns the angle between two polygons, assuming that all vertices of each polygon lie on a given plane. Hence, this is equivalent to estimating the angle between the planes formed by two polygons. The angle between two polygons is estimated by first estimating their orientation.- Parameters:
polygon1- 1st polygon.polygon2- 2nd polygon.- Returns:
- Angle between two polygons in radians.
- Throws:
CoincidentPointsException- Raised usually when it is determined that consecutive vertices of the polygon are too close (i.e. coincident) or when there are polygon degeneracies or numerical instabilities.- See Also:
-
getAngleBetweenPolygons
public static double getAngleBetweenPolygons(List<Point3D> vertices1, List<Point3D> vertices2, double threshold) throws CoincidentPointsException Returns the angle between two polygons formed each of them by the corresponding list of provided vertices and assuming that all vertices of each polygon lie on a given plane. Hence, this is equivalent to estimating the angle between the planes formed by two polygons. The angle between two polygons is estimated by first estimating their orientation.- Parameters:
vertices1- Vertices of 1st polygon.vertices2- 2nd polygon.threshold- Threshold to determine when polygon orientation can be estimated.- Returns:
- Angle between two polygons in radians.
- Throws:
IllegalArgumentException- Raised if provided threshold is negative or if list of vertices do not contain at least 3 vertices for each polygon.CoincidentPointsException- Raised usually when it is determined that consecutive vertices of the polygon are too close (i.e. coincident) or when there are polygon degeneracies or numerical instabilities.- See Also:
-
getAngleBetweenPolygons
public static double getAngleBetweenPolygons(List<Point3D> vertices1, List<Point3D> vertices2) throws CoincidentPointsException Returns the angle between two polygons formed each of them by the corresponding list of provided vertices and assuming that all vertices of each polygon lie on a given plane. Hence, this is equivalent to estimating the angle between the planes formed by two polygons. The angle between two polygons is estimated by first estimating their orientation.- Parameters:
vertices1- Vertices of 1st polygon.vertices2- 2nd polygon.- Returns:
- Angle between two polygons in radians.
- Throws:
IllegalArgumentException- Raised if list of vertices do not contain at least 3 vertices for each polygon.CoincidentPointsException- Raised usually when it is determined that consecutive vertices of the polygon are too close (i.e. coincident) or when there are polygon degeneracies or numerical instabilities.- See Also:
-
getAngleBetweenOrientations
private static double getAngleBetweenOrientations(double[] orientation1, double[] orientation2) Internal method to compute polygon orientation from their respective orientation vectors. Orientation vectors are provided as arrays and can be obtained by calling orientation(Polygon3D, double[]) among other methods.- Parameters:
orientation1- Orientation of 1st polygon.orientation2- Orientation of 2nd polygon.- Returns:
- Angle between two polygons in radians.
- Throws:
IllegalArgumentException- Raised if any of the orientation arrays do not have length 3.
-