public class Triangle extends Object
Modifier and Type | Field and Description |
---|---|
Coordinate |
p0
The coordinates of the vertices of the triangle
|
Coordinate |
p1
The coordinates of the vertices of the triangle
|
Coordinate |
p2
The coordinates of the vertices of the triangle
|
Constructor and Description |
---|
Triangle(Coordinate p0,
Coordinate p1,
Coordinate p2)
Creates a new triangle with the given vertices.
|
Modifier and Type | Method and 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.
|
double |
circumradius()
Computes the radius of the circumcircle of a triangle.
|
static double |
circumradius(Coordinate a,
Coordinate b,
Coordinate c)
Computes the radius of the circumcircle 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.
|
static boolean |
intersects(Coordinate a,
Coordinate b,
Coordinate c,
Coordinate p)
Tests whether a triangle intersects a point.
|
boolean |
isAcute()
Tests whether this triangle is acute.
|
static boolean |
isAcute(Coordinate a,
Coordinate b,
Coordinate c)
Tests whether a triangle is acute.
|
boolean |
isCCW()
Tests whether this triangle is oriented counter-clockwise.
|
static boolean |
isCCW(Coordinate a,
Coordinate b,
Coordinate c)
Tests whether a triangle is oriented counter-clockwise.
|
double |
length()
Computes the length of the perimeter of this triangle.
|
static double |
length(Coordinate a,
Coordinate b,
Coordinate c)
Compute the length of the perimeter of a triangle
|
double |
longestSideLength()
Computes the length of the longest side of this triangle
|
static double |
longestSideLength(Coordinate a,
Coordinate b,
Coordinate c)
Computes the length of the longest side of a triangle
|
static 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.
|
public Coordinate p0
public Coordinate p1
public Coordinate p2
public Triangle(Coordinate p0, Coordinate p1, Coordinate p2)
p0
- a vertexp1
- a vertexp2
- a vertexpublic static boolean isAcute(Coordinate a, Coordinate b, Coordinate c)
Note: this implementation is not robust for angles very close to 90 degrees.
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the trianglepublic static boolean isCCW(Coordinate a, Coordinate b, Coordinate c)
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the trianglepublic static boolean intersects(Coordinate a, Coordinate b, Coordinate c, Coordinate p)
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the trianglep
- the point to testpublic static HCoordinate perpendicularBisector(Coordinate a, Coordinate b)
a
- a pointb
- another pointpublic static double circumradius(Coordinate a, Coordinate b, Coordinate c)
Formula is as per https://math.stackexchange.com/a/3610959
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the trianglepublic static Coordinate circumcentre(Coordinate a, Coordinate b, Coordinate c)
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).
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the trianglepublic static Coordinate circumcentreDD(Coordinate a, Coordinate b, Coordinate c)
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 than circumcentre(Coordinate, Coordinate, Coordinate)
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the trianglepublic static Coordinate inCentre(Coordinate a, Coordinate b, Coordinate c)
The incentre always lies within the triangle.
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the trianglepublic static Coordinate centroid(Coordinate a, Coordinate b, Coordinate c)
The centroid always lies within the triangle.
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the trianglepublic static double length(Coordinate a, Coordinate b, Coordinate c)
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the trianglepublic static double longestSideLength(Coordinate a, Coordinate b, Coordinate c)
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the trianglepublic static Coordinate angleBisector(Coordinate a, Coordinate b, Coordinate c)
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the trianglepublic static double area(Coordinate a, Coordinate b, Coordinate c)
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the trianglesignedArea(Coordinate, Coordinate, Coordinate)
public static double signedArea(Coordinate a, Coordinate b, Coordinate c)
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.
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the triangleOrientation.index(Coordinate, Coordinate, Coordinate)
public static double area3D(Coordinate a, Coordinate b, Coordinate c)
a
- a vertex of the triangleb
- a vertex of the trianglec
- a vertex of the trianglepublic static double interpolateZ(Coordinate p, Coordinate v0, Coordinate v1, Coordinate v2)
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).
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 ordinatepublic Coordinate inCentre()
public boolean isAcute()
Note: this implementation is not robust for angles very close to 90 degrees.
public boolean isCCW()
public Coordinate circumcentre()
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).
public double circumradius()
public Coordinate centroid()
The centroid always lies within the triangle.
public double length()
public double longestSideLength()
public double area()
signedArea()
public double signedArea()
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.
Orientation.index(Coordinate, Coordinate, Coordinate)
public double area3D()
public double interpolateZ(Coordinate p)
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).
p
- the point to compute the Z-value ofCopyright © 2024. All rights reserved.