Class Triangle
- Namespace
- NetTopologySuite.Geometries
- Assembly
- NetTopologySuite.dll
Represents a planar triangle, and provides methods for calculating various properties of triangles.
public class Triangle
- Inheritance
-
Triangle
- Inherited Members
Constructors
Triangle(Coordinate, Coordinate, Coordinate)
Creates a new triangle with the given vertices.
public Triangle(Coordinate p0, Coordinate p1, Coordinate p2)
Parameters
p0
CoordinateA vertex
p1
CoordinateA vertex
p2
CoordinateA vertex
Properties
P0
A corner point of the triangle
public Coordinate P0 { get; set; }
Property Value
P1
A corner point of the triangle
public Coordinate P1 { get; set; }
Property Value
P2
A corner point of the triangle
public Coordinate P2 { get; set; }
Property Value
Methods
AngleBisector(Coordinate, Coordinate, Coordinate)
Computes the point at which the bisector of the angle ABC cuts the segment AC.
public static Coordinate AngleBisector(Coordinate a, Coordinate b, Coordinate c)
Parameters
a
CoordinateA vertex of the triangle
b
CoordinateA vertex of the triangle
c
CoordinateA vertex of the triangle
Returns
- Coordinate
The angle bisector cut point
Area()
Computes the 2D area of this triangle. The area value is always non-negative.
public double Area()
Returns
- double
The area of this triangle
- See Also
Area(Coordinate, Coordinate, Coordinate)
Computes the 2D area of a triangle. The area value is always non-negative.
public static double Area(Coordinate a, Coordinate b, Coordinate c)
Parameters
a
CoordinateA vertex of the triangle
b
CoordinateA vertex of the triangle
c
CoordinateA vertex of the triangle
Returns
- double
The area of the triangle
- See Also
Area3D()
Computes the 3D area of this triangle. The value computed is always non-negative.
public double Area3D()
Returns
- 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.
public static double Area3D(Coordinate a, Coordinate b, Coordinate c)
Parameters
a
CoordinateA vertex of the triangle
b
CoordinateA vertex of the triangle
c
CoordinateA vertex of the triangle
Returns
- 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.public Coordinate Centroid()
Returns
- Coordinate
The centroid of this triangle
Centroid(Coordinate, Coordinate, Coordinate)
Computes the centroid (centre of mass) of a triangle.
public static Coordinate Centroid(Coordinate a, Coordinate b, Coordinate c)
Parameters
a
CoordinateA vertex of the triangle
b
CoordinateA vertex of the triangle
c
CoordinateA vertex of the triangle
Returns
- 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).public Coordinate Circumcentre()
Returns
- Coordinate
The circumcentre of this triangle
Circumcentre(Coordinate, Coordinate, Coordinate)
Computes the circumcentre of a triangle.
public static Coordinate Circumcentre(Coordinate a, Coordinate b, Coordinate c)
Parameters
a
CoordinateA vertex of the triangle
b
CoordinateA vertex of the triangle
c
CoordinateA vertex of the triangle
Returns
- 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)public static Coordinate CircumcentreDD(Coordinate a, Coordinate b, Coordinate c)
Parameters
a
CoordinateA vertex of the triangle
b
CoordinateA vertex of the triangle
c
CoordinateA vertex of the triangle
Returns
- Coordinate
The circumcentre of the triangle
InCentre()
Computes the InCentre
of this triangle
public Coordinate InCentre()
Returns
- 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.
public static Coordinate InCentre(Coordinate a, Coordinate b, Coordinate c)
Parameters
a
CoordinateA vertex of the triangle
b
CoordinateA vertex of the triangle
c
CoordinateA vertex of the triangle
Returns
- 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).public double InterpolateZ(Coordinate p)
Parameters
p
CoordinateThe point to compute the Z-value of
Returns
- 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).public static double InterpolateZ(Coordinate p, Coordinate v0, Coordinate v1, Coordinate v2)
Parameters
p
CoordinateThe point to compute the Z-value of
v0
CoordinateA vertex of a triangle, with a Z ordinate
v1
CoordinateA vertex of a triangle, with a Z ordinate
v2
CoordinateA vertex of a triangle, with a Z ordinate
Returns
- double
The computed Z-value (elevation) of the point
Intersects(Coordinate, Coordinate, Coordinate, Coordinate)
Tests whether a triangle intersects a point.
public static bool Intersects(Coordinate a, Coordinate b, Coordinate c, Coordinate p)
Parameters
a
CoordinateA vertex of the triangle
b
CoordinateA vertex of the triangle
c
CoordinateA vertex of the triangle
p
CoordinateThe point to test
Returns
- bool
true
if the triangle intersects the point
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.public bool IsAcute()
Returns
- bool
true
if this triangle is acute
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.public static bool IsAcute(Coordinate a, Coordinate b, Coordinate c)
Parameters
a
CoordinateA vertex of the triangle
b
CoordinateA vertex of the triangle
c
CoordinateA vertex of the triangle
Returns
- bool
True if the triangle is acute.
IsCCW()
Tests whether this triangle is oriented counter-clockwise.
public bool IsCCW()
Returns
- bool
true
if the triangle orientation is counter-clockwise
IsCCW(Coordinate, Coordinate, Coordinate)
Tests whether a triangle is oriented counter-clockwise.
public static bool IsCCW(Coordinate a, Coordinate b, Coordinate c)
Parameters
a
CoordinateA vertex of the triangle
b
CoordinateA vertex of the triangle
c
CoordinateA vertex of the triangle
Returns
- bool
true
if the triangle orientation is counter-clockwise
Length()
Computes the length of the perimeter of this triangle.
public double Length()
Returns
- double
The length of the perimeter
Length(Coordinate, Coordinate, Coordinate)
Compute the length of the perimeter of a triangle
public static double Length(Coordinate a, Coordinate b, Coordinate c)
Parameters
a
CoordinateA vertex of the triangle
b
CoordinateA vertex of the triangle
c
CoordinateA vertex of the triangle
Returns
- double
The length of the perimeter of the triangle
LongestSideLength()
Computes the length of the longest side of this triangle
public double LongestSideLength()
Returns
- double
The length of the longest side of this triangle
LongestSideLength(Coordinate, Coordinate, Coordinate)
Computes the length of the longest side of a triangle
public static double LongestSideLength(Coordinate a, Coordinate b, Coordinate c)
Parameters
a
CoordinateA vertex of the triangle
b
CoordinateA vertex of the triangle
c
CoordinateA vertex of the triangle
Returns
- double
The length of the longest side of the triangle
PerpendicularBisector(Coordinate, Coordinate)
Computes the line which is the perpendicular bisector of the
public static HCoordinate PerpendicularBisector(Coordinate a, Coordinate b)
Parameters
a
CoordinateA point
b
CoordinateAnother point
Returns
- 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.public double SignedArea()
Returns
- double
The signed 2D area of this triangle
- See Also
SignedArea(Coordinate, Coordinate, Coordinate)
Computes the signed 2D area of a triangle.
public static double SignedArea(Coordinate a, Coordinate b, Coordinate c)
Parameters
a
CoordinateA vertex of the triangle
b
CoordinateA vertex of the triangle
c
CoordinateA vertex of the triangle
Returns
- 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.
- See Also