Class Triangle
Represents a planar triangle, and provides methods for calculating various properties of triangles.
Inherited Members
Namespace: NetTopologySuite.Geometries
Assembly: NetTopologySuite.dll
Syntax
public class Triangle
Constructors
| Improve this Doc View SourceTriangle(Coordinate, Coordinate, Coordinate)
Creates a new triangle with the given vertices.
Declaration
public Triangle(Coordinate p0, Coordinate p1, Coordinate p2)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p0 | A vertex |
Coordinate | p1 | A vertex |
Coordinate | p2 | A vertex |
Properties
| Improve this Doc View SourceP0
A corner point of the triangle
Declaration
public Coordinate P0 { get; set; }
Property Value
Type | Description |
---|---|
Coordinate |
P1
A corner point of the triangle
Declaration
public Coordinate P1 { get; set; }
Property Value
Type | Description |
---|---|
Coordinate |
P2
A corner point of the triangle
Declaration
public Coordinate P2 { get; set; }
Property Value
Type | Description |
---|---|
Coordinate |
Methods
| Improve this Doc View SourceAngleBisector(Coordinate, Coordinate, Coordinate)
Computes the point at which the bisector of the angle ABC cuts the segment AC.
Declaration
public static Coordinate AngleBisector(Coordinate a, Coordinate b, Coordinate c)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | a | A vertex of the triangle |
Coordinate | b | A vertex of the triangle |
Coordinate | c | A vertex of the triangle |
Returns
Type | Description |
---|---|
Coordinate | The angle bisector cut point |
Area()
Computes the 2D area of this triangle. The area value is always non-negative.
Declaration
public double Area()
Returns
Type | Description |
---|---|
Double | The area of this triangle |
See Also
| Improve this Doc View SourceArea(Coordinate, Coordinate, Coordinate)
Computes the 2D area of a triangle. The area value is always non-negative.
Declaration
public static double Area(Coordinate a, Coordinate b, Coordinate c)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | a | A vertex of the triangle |
Coordinate | b | A vertex of the triangle |
Coordinate | c | A vertex of the triangle |
Returns
Type | Description |
---|---|
Double | The area of the triangle |
See Also
| Improve this Doc View SourceArea3D()
Computes the 3D area of this triangle. The value computed is always non-negative.
Declaration
public double Area3D()
Returns
Type | Description |
---|---|
Double | The 3D area of this triangle |
Area3D(Coordinate, Coordinate, Coordinate)
Computes the 3D area of a triangle. The value computed is always non-negative.
Declaration
public static double Area3D(Coordinate a, Coordinate b, Coordinate c)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | a | A vertex of the triangle |
Coordinate | b | A vertex of the triangle |
Coordinate | c | A vertex of the triangle |
Returns
Type | Description |
---|---|
Double | The 3D area of the triangle |
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.
Declaration
public Coordinate Centroid()
Returns
Type | Description |
---|---|
Coordinate | The centroid of this triangle |
Centroid(Coordinate, Coordinate, Coordinate)
Computes the centroid (centre of mass) of a triangle.
Declaration
public static Coordinate Centroid(Coordinate a, Coordinate b, Coordinate c)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | a | A vertex of the triangle |
Coordinate | b | A vertex of the triangle |
Coordinate | c | A vertex of the triangle |
Returns
Type | Description |
---|---|
Coordinate | The centroid of the triangle |
Remarks
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.
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).
Declaration
public Coordinate Circumcentre()
Returns
Type | Description |
---|---|
Coordinate | The circumcentre of this triangle |
Circumcentre(Coordinate, Coordinate, Coordinate)
Computes the circumcentre of a triangle.
Declaration
public static Coordinate Circumcentre(Coordinate a, Coordinate b, Coordinate c)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | a | A vertex of the triangle |
Coordinate | b | A vertex of the triangle |
Coordinate | c | A vertex of the triangle |
Returns
Type | Description |
---|---|
Coordinate | The circumcentre of the triangle |
Remarks
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).
CircumcentreDD(Coordinate, Coordinate, Coordinate)
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 than Circumcentre(Coordinate, Coordinate, Coordinate)
Declaration
public static Coordinate CircumcentreDD(Coordinate a, Coordinate b, Coordinate c)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | a | A vertex of the triangle |
Coordinate | b | A vertex of the triangle |
Coordinate | c | A vertex of the triangle |
Returns
Type | Description |
---|---|
Coordinate | The circumcentre of the triangle |
InCentre()
Computes the InCentre
of this triangle
Declaration
public Coordinate InCentre()
Returns
Type | Description |
---|---|
Coordinate | The point which is the InCentre of the triangle. |
Remarks
The InCentre
of a triangle is the point which is equidistant
from the sides of the triangle.
This is also the point at which the bisectors of the 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.
InCentre(Coordinate, Coordinate, Coordinate)
Computes the incentre of a triangle.
Declaration
public static Coordinate InCentre(Coordinate a, Coordinate b, Coordinate c)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | a | A vertex of the triangle |
Coordinate | b | A vertex of the triangle |
Coordinate | c | A vertex of the triangle |
Returns
Type | Description |
---|---|
Coordinate | The point which is the incentre of the triangle |
Remarks
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.
InterpolateZ(Coordinate)
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).
Declaration
public double InterpolateZ(Coordinate p)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p | The point to compute the Z-value of |
Returns
Type | Description |
---|---|
Double | The computed Z-value (elevation) of the point |
InterpolateZ(Coordinate, Coordinate, Coordinate, Coordinate)
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).
Declaration
public static double InterpolateZ(Coordinate p, Coordinate v0, Coordinate v1, Coordinate v2)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p | The point to compute the Z-value of |
Coordinate | v0 | A vertex of a triangle, with a Z ordinate |
Coordinate | v1 | A vertex of a triangle, with a Z ordinate |
Coordinate | v2 | A vertex of a triangle, with a Z ordinate |
Returns
Type | Description |
---|---|
Double | The computed Z-value (elevation) of the point |
Intersects(Coordinate, Coordinate, Coordinate, Coordinate)
Tests whether a triangle intersects a point.
Declaration
public static bool Intersects(Coordinate a, Coordinate b, Coordinate c, Coordinate p)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | a | A vertex of the triangle |
Coordinate | b | A vertex of the triangle |
Coordinate | c | A vertex of the triangle |
Coordinate | p | The point to test |
Returns
Type | Description |
---|---|
Boolean |
|
IsAcute()
Tests whether this triangle is acute. A triangle is acute if 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.
Declaration
public bool IsAcute()
Returns
Type | Description |
---|---|
Boolean |
|
IsAcute(Coordinate, Coordinate, Coordinate)
Tests whether a triangle is acute. A triangle is acute if 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.
Declaration
public static bool IsAcute(Coordinate a, Coordinate b, Coordinate c)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | a | A vertex of the triangle |
Coordinate | b | A vertex of the triangle |
Coordinate | c | A vertex of the triangle |
Returns
Type | Description |
---|---|
Boolean | True if the triangle is acute. |
IsCCW()
Tests whether this triangle is oriented counter-clockwise.
Declaration
public bool IsCCW()
Returns
Type | Description |
---|---|
Boolean |
|
IsCCW(Coordinate, Coordinate, Coordinate)
Tests whether a triangle is oriented counter-clockwise.
Declaration
public static bool IsCCW(Coordinate a, Coordinate b, Coordinate c)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | a | A vertex of the triangle |
Coordinate | b | A vertex of the triangle |
Coordinate | c | A vertex of the triangle |
Returns
Type | Description |
---|---|
Boolean |
|
Length()
Computes the length of the perimeter of this triangle.
Declaration
public double Length()
Returns
Type | Description |
---|---|
Double | The length of the perimeter |
Length(Coordinate, Coordinate, Coordinate)
Compute the length of the perimeter of a triangle
Declaration
public static double Length(Coordinate a, Coordinate b, Coordinate c)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | a | A vertex of the triangle |
Coordinate | b | A vertex of the triangle |
Coordinate | c | A vertex of the triangle |
Returns
Type | Description |
---|---|
Double | The length of the perimeter of the triangle |
LongestSideLength()
Computes the length of the longest side of this triangle
Declaration
public double LongestSideLength()
Returns
Type | Description |
---|---|
Double | The length of the longest side of this triangle |
LongestSideLength(Coordinate, Coordinate, Coordinate)
Computes the length of the longest side of a triangle
Declaration
public static double LongestSideLength(Coordinate a, Coordinate b, Coordinate c)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | a | A vertex of the triangle |
Coordinate | b | A vertex of the triangle |
Coordinate | c | A vertex of the triangle |
Returns
Type | Description |
---|---|
Double | The length of the longest side of the triangle |
PerpendicularBisector(Coordinate, Coordinate)
Computes the line which is the perpendicular bisector of the
Declaration
public static HCoordinate PerpendicularBisector(Coordinate a, Coordinate b)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | a | A point |
Coordinate | b | Another point |
Returns
Type | Description |
---|---|
HCoordinate | The perpendicular bisector, as an HCoordinate line segment a-b. |
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 Index(Coordinate, Coordinate, Coordinate) for robust orientation calculation.
Declaration
public double SignedArea()
Returns
Type | Description |
---|---|
Double | The signed 2D area of this triangle |
See Also
| Improve this Doc View SourceSignedArea(Coordinate, Coordinate, Coordinate)
Computes the signed 2D area of a triangle.
Declaration
public static double SignedArea(Coordinate a, Coordinate b, Coordinate c)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | a | A vertex of the triangle |
Coordinate | b | A vertex of the triangle |
Coordinate | c | A vertex of the triangle |
Returns
Type | Description |
---|---|
Double | The area of the triangle |
Remarks
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 Index(Coordinate, Coordinate, Coordinate) for robust orientation calculation.