Class Triangle
- java.lang.Object
-
- org.locationtech.jts.geom.Triangle
-
public class Triangle extends java.lang.Object
Represents a planar triangle, and provides methods for calculating various properties of triangles.- Version:
- 1.7
-
-
Field Summary
Fields Modifier and Type Field Description Coordinate
p0
The coordinates of the vertices of the triangleCoordinate
p1
The coordinates of the vertices of the triangleCoordinate
p2
The coordinates of the vertices of the triangle
-
Constructor Summary
Constructors Constructor Description Triangle(Coordinate p0, Coordinate p1, Coordinate p2)
Creates a new triangle with the given vertices.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Coordinate
angleBisector(Coordinate a, Coordinate b, Coordinate c)
Computes the point at which the bisector of the angle ABC cuts the segment AC.double
area()
Computes the 2D area of this triangle.static double
area(Coordinate a, Coordinate b, Coordinate c)
Computes the 2D area of a triangle.double
area3D()
Computes the 3D area of this triangle.static double
area3D(Coordinate a, Coordinate b, Coordinate c)
Computes the 3D area of a triangle.Coordinate
centroid()
Computes the centroid (centre of mass) of this triangle.static Coordinate
centroid(Coordinate a, Coordinate b, Coordinate c)
Computes the centroid (centre of mass) of a triangle.Coordinate
circumcentre()
Computes the circumcentre of this triangle.static Coordinate
circumcentre(Coordinate a, Coordinate b, Coordinate c)
Computes the circumcentre of a triangle.static Coordinate
circumcentreDD(Coordinate a, Coordinate b, Coordinate c)
Computes the circumcentre of a triangle.Coordinate
inCentre()
Computes the incentre of this triangle.static Coordinate
inCentre(Coordinate a, Coordinate b, Coordinate c)
Computes the incentre of a triangle.double
interpolateZ(Coordinate p)
Computes the Z-value (elevation) of an XY point on a three-dimensional plane defined by this triangle (whose vertices must have Z-values).static double
interpolateZ(Coordinate p, Coordinate v0, Coordinate v1, Coordinate v2)
Computes the Z-value (elevation) of an XY point on a three-dimensional plane defined by a triangle whose vertices have Z-values.boolean
isAcute()
Tests whether this triangle is acute.static boolean
isAcute(Coordinate a, Coordinate b, Coordinate c)
Tests whether a triangle is acute.double
longestSideLength()
Computes the length of the longest side of this trianglestatic double
longestSideLength(Coordinate a, Coordinate b, Coordinate c)
Computes the length of the longest side of a trianglestatic HCoordinate
perpendicularBisector(Coordinate a, Coordinate b)
Computes the line which is the perpendicular bisector of the line segment a-b.double
signedArea()
Computes the signed 2D area of this triangle.static double
signedArea(Coordinate a, Coordinate b, Coordinate c)
Computes the signed 2D area of a triangle.
-
-
-
Field Detail
-
p0
public Coordinate p0
The coordinates of the vertices of the triangle
-
p1
public Coordinate p1
The coordinates of the vertices of the triangle
-
p2
public Coordinate p2
The coordinates of the vertices of the triangle
-
-
Constructor Detail
-
Triangle
public Triangle(Coordinate p0, Coordinate p1, Coordinate p2)
Creates a new triangle with the given vertices.- Parameters:
p0
- a vertexp1
- a vertexp2
- a vertex
-
-
Method Detail
-
isAcute
public static boolean isAcute(Coordinate a, Coordinate b, Coordinate c)
Tests whether a triangle is acute. A triangle is acute iff all interior angles are acute. This is a strict test - right triangles will return false A triangle which is not acute is either right or obtuse.Note: this implementation is not robust for angles very close to 90 degrees.
- Parameters:
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the triangle- Returns:
- true if the triangle is acute
-
perpendicularBisector
public static HCoordinate perpendicularBisector(Coordinate a, Coordinate b)
Computes the line which is the perpendicular bisector of the line segment a-b.- Parameters:
a
- a pointb
- another point- Returns:
- the perpendicular bisector, as an HCoordinate
-
circumcentre
public static Coordinate circumcentre(Coordinate a, Coordinate b, Coordinate c)
Computes the circumcentre of a triangle. The circumcentre is the centre of the circumcircle, the smallest circle which encloses the triangle. It is also the common intersection point of the perpendicular bisectors of the sides of the triangle, and is the only point which has equal distance to all three vertices of the triangle.The circumcentre does not necessarily lie within the triangle. For example, the circumcentre of an obtuse isosceles triangle lies outside the triangle.
This method uses an algorithm due to J.R.Shewchuk which uses normalization to the origin to improve the accuracy of computation. (See Lecture Notes on Geometric Robustness, Jonathan Richard Shewchuk, 1999).
- Parameters:
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the triangle- Returns:
- the circumcentre of the triangle
-
circumcentreDD
public static Coordinate circumcentreDD(Coordinate a, Coordinate b, Coordinate c)
Computes the circumcentre of a triangle. The circumcentre is the centre of the circumcircle, the smallest circle which encloses the triangle. It is also the common intersection point of the perpendicular bisectors of the sides of the triangle, and is the only point which has equal distance to all three vertices of the triangle.The circumcentre does not necessarily lie within the triangle. For example, the circumcentre of an obtuse isosceles triangle lies outside the triangle.
This method uses
DD
extended-precision arithmetic to provide more accurate results thancircumcentre(Coordinate, Coordinate, Coordinate)
- Parameters:
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the triangle- Returns:
- the circumcentre of the triangle
-
inCentre
public static Coordinate inCentre(Coordinate a, Coordinate b, Coordinate c)
Computes the incentre of a triangle. The inCentre of a triangle is the point which is equidistant from the sides of the triangle. It is also the point at which the bisectors of the triangle's angles meet. It is the centre of the triangle's incircle, which is the unique circle that is tangent to each of the triangle's three sides.The incentre always lies within the triangle.
- Parameters:
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the triangle- Returns:
- the point which is the incentre of the triangle
-
centroid
public static Coordinate centroid(Coordinate a, Coordinate b, Coordinate c)
Computes the centroid (centre of mass) of a triangle. This is also the point at which the triangle's three medians intersect (a triangle median is the segment from a vertex of the triangle to the midpoint of the opposite side). The centroid divides each median in a ratio of 2:1.The centroid always lies within the triangle.
- Parameters:
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the triangle- Returns:
- the centroid of the triangle
-
longestSideLength
public static double longestSideLength(Coordinate a, Coordinate b, Coordinate c)
Computes the length of the longest side of a triangle- Parameters:
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the triangle- Returns:
- the length of the longest side of the triangle
-
angleBisector
public static Coordinate angleBisector(Coordinate a, Coordinate b, Coordinate c)
Computes the point at which the bisector of the angle ABC cuts the segment AC.- Parameters:
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the triangle- Returns:
- the angle bisector cut point
-
area
public static double area(Coordinate a, Coordinate b, Coordinate c)
Computes the 2D area of a triangle. The area value is always non-negative.- Parameters:
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the triangle- Returns:
- the area of the triangle
- See Also:
signedArea(Coordinate, Coordinate, Coordinate)
-
signedArea
public static double signedArea(Coordinate a, Coordinate b, Coordinate c)
Computes the signed 2D area of a triangle. The area value is positive if the triangle is oriented CW, and negative if it is oriented CCW.The signed area value can be used to determine point orientation, but the implementation in this method is susceptible to round-off errors. Use
Orientation.index(Coordinate, Coordinate, Coordinate)
for robust orientation calculation.- Parameters:
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the triangle- Returns:
- the signed 2D area of the triangle
- See Also:
Orientation.index(Coordinate, Coordinate, Coordinate)
-
area3D
public static double area3D(Coordinate a, Coordinate b, Coordinate c)
Computes the 3D area of a triangle. The value computed is always non-negative.- Parameters:
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the triangle- Returns:
- the 3D area of the triangle
-
interpolateZ
public static double interpolateZ(Coordinate p, Coordinate v0, Coordinate v1, Coordinate v2)
Computes the Z-value (elevation) of an XY point on a three-dimensional plane defined by a triangle whose vertices have Z-values. The defining triangle must not be degenerate (in other words, the triangle must enclose a non-zero area), and must not be parallel to the Z-axis.This method can be used to interpolate the Z-value of a point inside a triangle (for example, of a TIN facet with elevations on the vertices).
- Parameters:
p
- the point to compute the Z-value ofv0
- a vertex of a triangle, with a Z ordinatev1
- a vertex of a triangle, with a Z ordinatev2
- a vertex of a triangle, with a Z ordinate- Returns:
- the computed Z-value (elevation) of the point
-
inCentre
public Coordinate inCentre()
Computes the incentre of this triangle. The incentre of a triangle is the point which is equidistant from the sides of the triangle. It is also the point at which the bisectors of the triangle's angles meet. It is the centre of the triangle's incircle, which is the unique circle that is tangent to each of the triangle's three sides.- Returns:
- the point which is the inCentre of this triangle
-
isAcute
public boolean isAcute()
Tests whether this triangle is acute. A triangle is acute iff all interior angles are acute. This is a strict test - right triangles will return false A triangle which is not acute is either right or obtuse.Note: this implementation is not robust for angles very close to 90 degrees.
- Returns:
- true if this triangle is acute
-
circumcentre
public Coordinate circumcentre()
Computes the circumcentre of this triangle. The circumcentre is the centre of the circumcircle, the smallest circle which encloses the triangle. It is also the common intersection point of the perpendicular bisectors of the sides of the triangle, and is the only point which has equal distance to all three vertices of the triangle.The circumcentre does not necessarily lie within the triangle.
This method uses an algorithm due to J.R.Shewchuk which uses normalization to the origin to improve the accuracy of computation. (See Lecture Notes on Geometric Robustness, Jonathan Richard Shewchuk, 1999).
- Returns:
- the circumcentre of this triangle
-
centroid
public Coordinate centroid()
Computes the centroid (centre of mass) of this triangle. This is also the point at which the triangle's three medians intersect (a triangle median is the segment from a vertex of the triangle to the midpoint of the opposite side). The centroid divides each median in a ratio of 2:1.The centroid always lies within the triangle.
- Returns:
- the centroid of this triangle
-
longestSideLength
public double longestSideLength()
Computes the length of the longest side of this triangle- Returns:
- the length of the longest side of this triangle
-
area
public double area()
Computes the 2D area of this triangle. The area value is always non-negative.- Returns:
- the area of this triangle
- See Also:
signedArea()
-
signedArea
public double signedArea()
Computes the signed 2D area of this triangle. The area value is positive if the triangle is oriented CW, and negative if it is oriented CCW.The signed area value can be used to determine point orientation, but the implementation in this method is susceptible to round-off errors. Use
Orientation.index(Coordinate, Coordinate, Coordinate)
for robust orientation calculation.- Returns:
- the signed 2D area of this triangle
- See Also:
Orientation.index(Coordinate, Coordinate, Coordinate)
-
area3D
public double area3D()
Computes the 3D area of this triangle. The value computed is always non-negative.- Returns:
- the 3D area of this triangle
-
interpolateZ
public double interpolateZ(Coordinate p)
Computes the Z-value (elevation) of an XY point on a three-dimensional plane defined by this triangle (whose vertices must have Z-values). This triangle must not be degenerate (in other words, the triangle must enclose a non-zero area), and must not be parallel to the Z-axis.This method can be used to interpolate the Z-value of a point inside this triangle (for example, of a TIN facet with elevations on the vertices).
- Parameters:
p
- the point to compute the Z-value of- Returns:
- the computed Z-value (elevation) of the point
-
-