Package com.irurueta.geometry
Class Triangle2D
java.lang.Object
com.irurueta.geometry.Triangle2D
- All Implemented Interfaces:
Serializable
This class defines a triangle in the 2D space.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleDefault threshold value.static final doubleMinimum allowed threshold value.static final intConstant defining number of vertices on a triangle.private Point2D1st vertex of this triangle.private Point2D2nd vertex of this triangle.private Point2D3rd vertex of this triangle. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleReturns area of a triangle formed by provided vertices.static doublearea(Triangle2D triangle) Returns area of provided triangle.booleanIndicates whether the vertices of this triangle are provided in clockwise order or not.booleanareVerticesClockwise(double threshold) Indicates whether the vertices of this triangle are provided in clockwise order or not.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 Point2DComputes 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 Point2Dcenter(Triangle2D t) Computes the center of provided triangle.static voidcenter(Triangle2D t, Point2D result) Computes the center of provided triangle and stores the result in provided result point.voidclosestPoint(Point2D point, Point2D result) Computes the point which is locus of this triangle closest to provided point and stores the result in provided result point.voidclosestPoint(Point2D point, Point2D 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.doublegetArea()Returns area of this triangle.Returns center of this triangle, which is the result of averaging its vertices.getClosestPoint(Point2D point) Returns the point which is locus of this triangle closest to provided point.getClosestPoint(Point2D point, double threshold) Returns the point which is locus of this triangle (up to a certain threshold) closest to provided point.doubleReturns perimeter of this triangle.doublegetShortestDistance(Point2D 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.doubleReturns area of this triangle with sign.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(Triangle2D triangle, Point2D point) Indicates whether provided point lies inside provided triangle or not.static booleanisInside(Triangle2D triangle, Point2D 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.static doubleReturns perimeter of triangle formed by provided vertices.static doubleperimeter(Triangle2D triangle) Returns perimeter of provided triangle.voidsetVertex1(Point2D vertex1) Sets 1st vertex of this triangle.voidsetVertex2(Point2D vertex2) Sets 2nd vertex of this triangle.voidsetVertex3(Point2D vertex3) Sets 3rd vertex of this triangle.final voidsetVertices(Point2D vertex1, Point2D vertex2, Point2D vertex3) Sets all vertices of this triangle.static doubleshortestDistance(Point2D vertex1, Point2D vertex2, Point2D vertex3, Point2D 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(Triangle2D triangle, Point2D point) Computes the shortest distance from a given point to the boundaries of provided triangle, considering its boundaries as lines with a finite length.static doublesignedArea(Point2D vertex1, Point2D vertex2, Point2D vertex3) Returns area with sign of the triangle formed by provided vertices.static doublesignedArea(Triangle2D triangle) Returns area of provided triangle with sign.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 it's locus or not, etc.- See Also:
-
MIN_THRESHOLD
public static final double MIN_THRESHOLDMinimum allowed threshold value.- 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
-
Triangle2D
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.
-
signedArea
Returns area of provided triangle with sign. If vertices are defined clockwise area is positive, otherwise returned area is negative.- Parameters:
triangle- Triangle to be evaluated.- Returns:
- Area of triangle with sign. Positive sign indicates that vertices are clockwise, negative sign indicates that vertices are counterclockwise.
-
signedArea
Returns area with sign of the triangle formed by provided vertices. If vertices are defined clockwise area is negative, otherwise returned area is positive.- Parameters:
vertex1- 1st vertex of a triangle.vertex2- 2nd vertex of a triangle.vertex3- 3rd vertex of a triangle.- Returns:
- Area of a triangle with sign. Negative sign indicates that vertices are clockwise, positive sign indicates that vertices are counterclockwise.
-
getSignedArea
public double getSignedArea()Returns area of this triangle with sign. If vertices are defined clockwise area is positive, otherwise returned area is negative.- Returns:
- Area of this triangle with sign. Positive sign indicates that vertices are clockwise, negative sign indicates that vertices are counterclockwise.
-
area
Returns area of provided triangle.- Parameters:
triangle- Triangle to be checked.- Returns:
- Area of triangle.
-
area
Returns area of a 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.- 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.- 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.- 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.- 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.- 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(Point2D vertex1, Point2D vertex2, Point2D vertex3, Point2D point, double threshold) Indicates whether provided point lies inside a triangle formed by provided vertices or not 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.
-
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(Point2D vertex1, Point2D vertex2, Point2D vertex3, Point2D 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.
-
areVerticesClockwise
public boolean areVerticesClockwise(double threshold) Indicates whether the vertices of this triangle are provided in clockwise order or not. Vertices of a triangle are in clockwise order when the triangle's signed area is negative.- Parameters:
threshold- Threshold to determine if vertices are clockwise or not. This should usually be 0.0 and there is no restriction in sign- Returns:
- True if vertices of this triangle are in clockwise order, false if they are in counterclockwise order.
-
areVerticesClockwise
public boolean areVerticesClockwise()Indicates whether the vertices of this triangle are provided in clockwise order or not.- Returns:
- True if vertices of this triangle are in clockwise order, false if they are in counterclockwise order.
-