Class AngleUtility
- Namespace
- NetTopologySuite.Algorithm
- Assembly
- NetTopologySuite.dll
Utility functions for working with angles. Unless otherwise noted, methods in this class express angles in radians.
public static class AngleUtility
- Inheritance
-
AngleUtility
- Inherited Members
Fields
PiOver2
Value of Pi / 2
public const double PiOver2 = 1.5707963267948966
Field Value
PiOver4
Value of Pi / 4
public const double PiOver4 = 0.7853981633974483
Field Value
PiTimes2
Value of 2 * Pi
public const double PiTimes2 = 6.283185307179586
Field Value
Methods
Angle(Coordinate)
Returns the angle of the vector from (0,0) to p, relative to the positive X-axis.
public static double Angle(Coordinate p)
Parameters
p
CoordinateThe terminal point of the vector.
Returns
- double
The normalized angle (in radians) that (0,0)-p makes with the positive X-axis.
Remarks
The angle is normalized to be in the range ( -Pi, Pi ].
Angle(Coordinate, Coordinate)
Returns the angle of the vector from p0 to p1, relative to the positive X-axis.
public static double Angle(Coordinate p0, Coordinate p1)
Parameters
p0
CoordinateThe initial point of the vector.
p1
CoordinateThe terminal point of the vector.
Returns
- double
The normalized angle (in radians) that p0-p1 makes with the positive X-axis
Remarks
The angle is normalized to be in the range [ -Pi, Pi ].
AngleBetween(Coordinate, Coordinate, Coordinate)
Returns the unoriented smallest angle between two vectors.
public static double AngleBetween(Coordinate tip1, Coordinate tail, Coordinate tip2)
Parameters
tip1
CoordinateThe tip of one vector
tail
CoordinateThe tail of each vector
tip2
CoordinateThe tip of the other vector
Returns
Remarks
The computed angle will be in the range [0, Pi).
AngleBetweenOriented(Coordinate, Coordinate, Coordinate)
Returns the oriented smallest angle between two vectors. The computed angle will be in the range (-Pi, Pi]. A positive result corresponds to a CounterClockwise rotation (CCW) from v1 to v2; a negative result corresponds to a Clockwise (CW) rotation; a zero result corresponds to no rotation.
public static double AngleBetweenOriented(Coordinate tip1, Coordinate tail, Coordinate tip2)
Parameters
tip1
CoordinateThe tip of v1
tail
CoordinateThe tail of each vector
tip2
CoordinateThe tip of v2
Returns
- double
The angle between v1 and v2, relative to v1
Bisector(Coordinate, Coordinate, Coordinate)
Computes the angle of the unoriented bisector of the smallest angle between two vectors.
public static double Bisector(Coordinate tip1, Coordinate tail, Coordinate tip2)
Parameters
tip1
CoordinateThe tip of v1
tail
CoordinateThe tail of each vector
tip2
CoordinateThe tip of v2
Returns
- double
The angle of the bisector between v1 and v2
Remarks
The computed angle will be in the range (-Pi, Pi].
Diff(double, double)
Computes the unoriented smallest difference between two angles.
public static double Diff(double ang1, double ang2)
Parameters
ang1
doubleThe angle of one vector (in [-Pi, Pi] )
ang2
doubleThe angle of the other vector (in range [-Pi, Pi] )
Returns
- double
The angle (in radians) between the two vectors (in range [0, Pi] )
Remarks
- The angles are assumed to be normalized to the range [-Pi, Pi].
- The result will be in the range [0, Pi].
GetTurn(double, double)
Returns whether an angle must turn clockwise or counterclockwise to overlap another angle.
public static OrientationIndex GetTurn(double ang1, double ang2)
Parameters
Returns
- OrientationIndex
Whether a1 must turn Clockwise, CounterClockwise or None to overlap a2.
InteriorAngle(Coordinate, Coordinate, Coordinate)
Computes the interior angle between two segments of a ring. The ring is assumed to be oriented in a clockwise direction.
public static double InteriorAngle(Coordinate p0, Coordinate p1, Coordinate p2)
Parameters
p0
CoordinateA point of the ring
p1
CoordinateThe next point of the ring
p2
CoordinateThe next point of the ring
Returns
- double
The interior angle based at
p1
Remarks
The computed angle will be in the range [0, 2Pi]
IsAcute(Coordinate, Coordinate, Coordinate)
Tests whether the angle between p0-p1-p2 is acute.
public static bool IsAcute(Coordinate p0, Coordinate p1, Coordinate p2)
Parameters
p0
CoordinateAn endpoint of the angle
p1
CoordinateThe base of the angle
p2
CoordinateAnother endpoint of the angle
Returns
Remarks
An angle is acute if it is less than 90 degrees.
Note: this implementation is not precise (deterministic) for angles very close to 90 degrees.
IsObtuse(Coordinate, Coordinate, Coordinate)
Tests whether the angle between p0-p1-p2 is obtuse
public static bool IsObtuse(Coordinate p0, Coordinate p1, Coordinate p2)
Parameters
p0
CoordinateAn endpoint of the angle
p1
CoordinateThe base of the angle
p2
CoordinateAnother endpoint of the angle
Returns
Remarks
An angle is obtuse if it is greater than 90 degrees.
Note: this implementation is not precise (deterministic) for angles very close to 90 degrees.
Normalize(double)
Computes the normalized value of an angle, which is the equivalent angle in the range ( -Pi, Pi ].
public static double Normalize(double angle)
Parameters
angle
doubleThe angle to normalize
Returns
- double
An equivalent angle in the range (-Pi, Pi]
NormalizePositive(double)
Computes the normalized positive value of an angle, which is the equivalent angle in the range [ 0, 2*Pi ).
E.g.Function call | Result |
---|---|
NormalizePositive(0.0) | 0.0 |
NormalizePositive(-PI) | PI |
NormalizePositive(-2PI) | 0.0 |
NormalizePositive(-3PI) | PI |
NormalizePositive(-4PI) | 0.0 |
NormalizePositive(PI) | PI |
NormalizePositive(2PI) | 0.0 |
NormalizePositive(3PI) | PI |
NormalizePositive(4PI) | 0.0 |
public static double NormalizePositive(double angle)
Parameters
angle
doubleThe angle to normalize, in radians.
Returns
- double
An equivalent positive angle
Project(Coordinate, double, double)
Projects a point by a given angle and distance.
public static Coordinate Project(Coordinate p, double angle, double dist)
Parameters
p
CoordinateThe point to project
angle
doubleThe angle at which to project
dist
doubleThe distance to project
Returns
- Coordinate
The projected point
ToDegrees(double)
Converts from radians to degrees.
public static double ToDegrees(double radians)
Parameters
radians
doubleAn angle in radians
Returns
- double
The angle in degrees
ToRadians(double)
Converts from degrees to radians.
public static double ToRadians(double angleDegrees)
Parameters
angleDegrees
doubleAn angle in degrees
Returns
- double
The angle in radians