Class AngleUtility
Utility functions for working with angles. Unless otherwise noted, methods in this class express angles in radians.
Inherited Members
Namespace: NetTopologySuite.Algorithm
Assembly: NetTopologySuite.dll
Syntax
public static class AngleUtility
Fields
| Improve this Doc View SourcePiOver2
Value of Pi / 2
Declaration
public const double PiOver2 = 1.5707963267948966
Field Value
Type | Description |
---|---|
Double |
PiOver4
Value of Pi / 4
Declaration
public const double PiOver4 = 0.78539816339744828
Field Value
Type | Description |
---|---|
Double |
PiTimes2
Value of 2 * Pi
Declaration
public const double PiTimes2 = 6.2831853071795862
Field Value
Type | Description |
---|---|
Double |
Methods
| Improve this Doc View SourceAngle(Coordinate)
Returns the angle of the vector from (0,0) to p, relative to the positive X-axis.
Declaration
public static double Angle(Coordinate p)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p | The terminal point of the vector. |
Returns
Type | Description |
---|---|
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.
Declaration
public static double Angle(Coordinate p0, Coordinate p1)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p0 | The initial point of the vector. |
Coordinate | p1 | The terminal point of the vector. |
Returns
Type | Description |
---|---|
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.
Declaration
public static double AngleBetween(Coordinate tip1, Coordinate tail, Coordinate tip2)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | tip1 | The tip of one vector |
Coordinate | tail | The tail of each vector |
Coordinate | tip2 | The tip of the other vector |
Returns
Type | Description |
---|---|
Double |
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.
Declaration
public static double AngleBetweenOriented(Coordinate tip1, Coordinate tail, Coordinate tip2)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | tip1 | The tip of v1 |
Coordinate | tail | The tail of each vector |
Coordinate | tip2 | The tip of v2 |
Returns
Type | Description |
---|---|
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.
Declaration
public static double Bisector(Coordinate tip1, Coordinate tail, Coordinate tip2)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | tip1 | The tip of v1 |
Coordinate | tail | The tail of each vector |
Coordinate | tip2 | The tip of v2 |
Returns
Type | Description |
---|---|
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.
Declaration
public static double Diff(double ang1, double ang2)
Parameters
Type | Name | Description |
---|---|---|
Double | ang1 | The angle of one vector (in [-Pi, Pi] ) |
Double | ang2 | The angle of the other vector (in range [-Pi, Pi] ) |
Returns
Type | Description |
---|---|
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.
Declaration
public static OrientationIndex GetTurn(double ang1, double ang2)
Parameters
Type | Name | Description |
---|---|---|
Double | ang1 | An angle (in radians) |
Double | ang2 | An angle (in radians) |
Returns
Type | Description |
---|---|
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.
Declaration
public static double InteriorAngle(Coordinate p0, Coordinate p1, Coordinate p2)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p0 | A point of the ring |
Coordinate | p1 | The next point of the ring |
Coordinate | p2 | The next point of the ring |
Returns
Type | Description |
---|---|
Double | The interior angle based at |
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.
Declaration
public static bool IsAcute(Coordinate p0, Coordinate p1, Coordinate p2)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p0 | An endpoint of the angle |
Coordinate | p1 | The base of the angle |
Coordinate | p2 | Another endpoint of the angle |
Returns
Type | Description |
---|---|
Boolean | true if the angle is acute. |
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
Declaration
public static bool IsObtuse(Coordinate p0, Coordinate p1, Coordinate p2)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p0 | An endpoint of the angle |
Coordinate | p1 | The base of the angle |
Coordinate | p2 | Another endpoint of the angle |
Returns
Type | Description |
---|---|
Boolean | true if the angle is obtuse. |
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 ].
Declaration
public static double Normalize(double angle)
Parameters
Type | Name | Description |
---|---|---|
Double | angle | The angle to normalize |
Returns
Type | Description |
---|---|
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 |
Declaration
public static double NormalizePositive(double angle)
Parameters
Type | Name | Description |
---|---|---|
Double | angle | The angle to normalize, in radians. |
Returns
Type | Description |
---|---|
Double | An equivalent positive angle |
Project(Coordinate, Double, Double)
Projects a point by a given angle and distance.
Declaration
public static Coordinate Project(Coordinate p, double angle, double dist)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p | The point to project |
Double | angle | The angle at which to project |
Double | dist | The distance to project |
Returns
Type | Description |
---|---|
Coordinate | The projected point |
ToDegrees(Double)
Converts from radians to degrees.
Declaration
public static double ToDegrees(double radians)
Parameters
Type | Name | Description |
---|---|---|
Double | radians | An angle in radians |
Returns
Type | Description |
---|---|
Double | The angle in degrees |
ToRadians(Double)
Converts from degrees to radians.
Declaration
public static double ToRadians(double angleDegrees)
Parameters
Type | Name | Description |
---|---|---|
Double | angleDegrees | An angle in degrees |
Returns
Type | Description |
---|---|
Double | The angle in radians |