Package org.locationtech.jts.algorithm
Class Angle
- java.lang.Object
-
- org.locationtech.jts.algorithm.Angle
-
public class Angle extends java.lang.Object
Utility functions for working with angles. Unless otherwise noted, methods in this class express angles in radians.
-
-
Field Summary
Fields Modifier and Type Field Description static int
CLOCKWISE
Constant representing clockwise orientationstatic int
COUNTERCLOCKWISE
Constant representing counterclockwise orientationstatic int
NONE
Constant representing no orientationstatic double
PI_OVER_2
The value of Pi/2static double
PI_OVER_4
The value of Pi/4static double
PI_TIMES_2
The value of 2*Pi
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double
angle(Coordinate p)
Returns the angle of the vector from (0,0) to p, relative to the positive X-axis.static double
angle(Coordinate p0, Coordinate p1)
Returns the angle of the vector from p0 to p1, relative to the positive X-axis.static double
angleBetween(Coordinate tip1, Coordinate tail, Coordinate tip2)
Returns the unoriented smallest angle between two vectors.static double
angleBetweenOriented(Coordinate tip1, Coordinate tail, Coordinate tip2)
Returns the oriented smallest angle between two vectors.static double
bisector(Coordinate tip1, Coordinate tail, Coordinate tip2)
Computes the angle of the unoriented bisector of the smallest angle between two vectors.static double
diff(double ang1, double ang2)
Computes the unoriented smallest difference between two angles.static int
getTurn(double ang1, double ang2)
Returns whether an angle must turn clockwise or counterclockwise to overlap another angle.static double
interiorAngle(Coordinate p0, Coordinate p1, Coordinate p2)
Computes the interior angle between two segments of a ring.static boolean
isAcute(Coordinate p0, Coordinate p1, Coordinate p2)
Tests whether the angle between p0-p1-p2 is acute.static boolean
isObtuse(Coordinate p0, Coordinate p1, Coordinate p2)
Tests whether the angle between p0-p1-p2 is obtuse.static double
normalize(double angle)
Computes the normalized value of an angle, which is the equivalent angle in the range ( -Pi, Pi ].static double
normalizePositive(double angle)
Computes the normalized positive value of an angle, which is the equivalent angle in the range [ 0, 2*Pi ).static Coordinate
project(Coordinate p, double angle, double dist)
Projects a point by a given angle and distance.static double
toDegrees(double radians)
Converts from radians to degrees.static double
toRadians(double angleDegrees)
Converts from degrees to radians.
-
-
-
Field Detail
-
PI_TIMES_2
public static final double PI_TIMES_2
The value of 2*Pi- See Also:
- Constant Field Values
-
PI_OVER_2
public static final double PI_OVER_2
The value of Pi/2- See Also:
- Constant Field Values
-
PI_OVER_4
public static final double PI_OVER_4
The value of Pi/4- See Also:
- Constant Field Values
-
COUNTERCLOCKWISE
public static final int COUNTERCLOCKWISE
Constant representing counterclockwise orientation- See Also:
- Constant Field Values
-
CLOCKWISE
public static final int CLOCKWISE
Constant representing clockwise orientation- See Also:
- Constant Field Values
-
NONE
public static final int NONE
Constant representing no orientation- See Also:
- Constant Field Values
-
-
Method Detail
-
toDegrees
public static double toDegrees(double radians)
Converts from radians to degrees.- Parameters:
radians
- an angle in radians- Returns:
- the angle in degrees
-
toRadians
public static double toRadians(double angleDegrees)
Converts from degrees to radians.- Parameters:
angleDegrees
- an angle in degrees- Returns:
- the angle in radians
-
angle
public static double angle(Coordinate p0, Coordinate p1)
Returns the angle of the vector from p0 to p1, relative to the positive X-axis. The angle is normalized to be in the range [ -Pi, Pi ].- Parameters:
p0
- the initial point of the vectorp1
- the terminal point of the vector- Returns:
- the normalized angle (in radians) that p0-p1 makes with the positive x-axis.
-
angle
public static double angle(Coordinate p)
Returns the angle of the vector from (0,0) to p, relative to the positive X-axis. The angle is normalized to be in the range ( -Pi, Pi ].- Parameters:
p
- the terminal point of the vector- Returns:
- the normalized angle (in radians) that p makes with the positive x-axis.
-
isAcute
public static boolean isAcute(Coordinate p0, Coordinate p1, Coordinate p2)
Tests whether the angle between p0-p1-p2 is acute. 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.
- Parameters:
p0
- an endpoint of the anglep1
- the base of the anglep2
- the other endpoint of the angle- Returns:
- true if the angle is acute
-
isObtuse
public static boolean isObtuse(Coordinate p0, Coordinate p1, Coordinate p2)
Tests whether the angle between p0-p1-p2 is obtuse. 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.
- Parameters:
p0
- an endpoint of the anglep1
- the base of the anglep2
- the other endpoint of the angle- Returns:
- true if the angle is obtuse
-
angleBetween
public static double angleBetween(Coordinate tip1, Coordinate tail, Coordinate tip2)
Returns the unoriented smallest angle between two vectors. The computed angle will be in the range [0, Pi).- Parameters:
tip1
- the tip of one vectortail
- the tail of each vectortip2
- the tip of the other vector- Returns:
- the angle between tail-tip1 and tail-tip2
-
angleBetweenOriented
public static double angleBetweenOriented(Coordinate tip1, Coordinate tail, Coordinate tip2)
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 (CCW) rotation from v1 to v2; a negative result corresponds to a clockwise (CW) rotation; a zero result corresponds to no rotation.- Parameters:
tip1
- the tip of v1tail
- the tail of each vectortip2
- the tip of v2- Returns:
- the angle between v1 and v2, relative to v1
-
bisector
public static double bisector(Coordinate tip1, Coordinate tail, Coordinate tip2)
Computes the angle of the unoriented bisector of the smallest angle between two vectors. The computed angle will be in the range (-Pi, Pi].- Parameters:
tip1
- the tip of v1tail
- the tail of each vectortip2
- the tip of v2- Returns:
- the angle of the bisector between v1 and v2
-
interiorAngle
public static double interiorAngle(Coordinate p0, Coordinate p1, Coordinate p2)
Computes the interior angle between two segments of a ring. The ring is assumed to be oriented in a clockwise direction. The computed angle will be in the range [0, 2Pi]- Parameters:
p0
- a point of the ringp1
- the next point of the ringp2
- the next point of the ring- Returns:
- the interior angle based at
p1
-
getTurn
public static int getTurn(double ang1, double ang2)
Returns whether an angle must turn clockwise or counterclockwise to overlap another angle.- Parameters:
ang1
- an angle (in radians)ang2
- an angle (in radians)- Returns:
- whether a1 must turn CLOCKWISE, COUNTERCLOCKWISE or NONE to overlap a2.
-
normalize
public static double normalize(double angle)
Computes the normalized value of an angle, which is the equivalent angle in the range ( -Pi, Pi ].- Parameters:
angle
- the angle to normalize- Returns:
- an equivalent angle in the range (-Pi, Pi]
-
normalizePositive
public static double normalizePositive(double angle)
Computes the normalized positive value of an angle, which is the equivalent angle in the range [ 0, 2*Pi ). E.g.:- normalizePositive(0.0) = 0.0
- normalizePositive(-PI) = PI
- normalizePositive(-2PI) = 0.0
- normalizePositive(-3PI) = PI
- normalizePositive(-4PI) = 0
- normalizePositive(PI) = PI
- normalizePositive(2PI) = 0.0
- normalizePositive(3PI) = PI
- normalizePositive(4PI) = 0.0
- Parameters:
angle
- the angle to normalize, in radians- Returns:
- an equivalent positive angle
-
diff
public static double diff(double ang1, double ang2)
Computes the unoriented smallest difference between two angles. The angles are assumed to be normalized to the range [-Pi, Pi]. The result will be in the range [0, Pi].- Parameters:
ang1
- the angle of one vector (in [-Pi, Pi] )ang2
- the angle of the other vector (in range [-Pi, Pi] )- Returns:
- the angle (in radians) between the two vectors (in range [0, Pi] )
-
project
public static Coordinate project(Coordinate p, double angle, double dist)
Projects a point by a given angle and distance.- Parameters:
p
- the point to projectangle
- the angle at which to projectdist
- the distance to project- Returns:
- the projected point
-
-