geos::algorithm::Angle Class Reference

Utility functions for working with angles. More...

`#include <Angle.h>`

## Static Public Member Functions

static double | toDegrees (double radians)
static double | toRadians (double angleDegrees)
static double | angle (const geom::CoordinateXY &p0, const geom::CoordinateXY &p1)
| Returns the angle of the vector from p0 to p1, relative to the positive X-axis.
static double | angle (const geom::CoordinateXY &p)
| Returns the angle that the vector from (0,0) to p, relative to the positive X-axis.
static bool | isAcute (const geom::CoordinateXY &p0, const geom::CoordinateXY &p1, const geom::CoordinateXY &p2)
static bool | isObtuse (const geom::CoordinateXY &p0, const geom::CoordinateXY &p1, const geom::CoordinateXY &p2)
static double | angleBetween (const geom::CoordinateXY &tip1, const geom::CoordinateXY &tail, const geom::CoordinateXY &tip2)
static double | angleBetweenOriented (const geom::CoordinateXY &tip1, const geom::CoordinateXY &tail, const geom::CoordinateXY &tip2)
static double | bisector (const geom::CoordinateXY &tip1, const geom::CoordinateXY &tail, const geom::CoordinateXY &tip2)
static double | interiorAngle (const geom::CoordinateXY &p0, const geom::CoordinateXY &p1, const geom::CoordinateXY &p2)
static int | getTurn (double ang1, double ang2)
| Returns whether an angle must turn clockwise or counterclockwise to overlap another angle.
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 double | diff (double ang1, double ang2)
static void | sinCosSnap (const double ang, double &rSin, double &rCos)
| Computes both sin and cos of an angle, snapping near-zero values to zero.
static geom::CoordinateXY | project (const geom::CoordinateXY &p, double angle, double dist)

## Static Public Attributes

static constexpr double | PI_TIMES_2 = 2.0 * MATH_PI
static constexpr double | PI_OVER_2 = MATH_PI / 2.0
static constexpr double | PI_OVER_4 = MATH_PI / 4.0
static const int | COUNTERCLOCKWISE = Orientation::COUNTERCLOCKWISE
| Constant representing counterclockwise orientation.
static const int | CLOCKWISE = Orientation::CLOCKWISE
| Constant representing clockwise orientation.
static const int | NONE = Orientation::COLLINEAR
| Constant representing no orientation.

## Detailed Description

Utility functions for working with angles.

Unless otherwise noted, methods in this class express angles in radians.

## Member Function Documentation

## angle() [1/2]

double geos::algorithm::Angle::angle | ( | const geom::CoordinateXY & | p | ) |

static

Returns the angle that the vector from (0,0) to p, relative to the positive X-axis.

The angle is normalized to be in the range ( -Pi, Pi ].

Returns
  the normalized angle (in radians) that p makes with the positive x-axis.

## angle() [2/2]

double geos::algorithm::Angle::angle | ( | const geom::CoordinateXY & | p0,
|  | const geom::CoordinateXY & | p1 )

static

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 ].

Returns
  the normalized angle (in radians) that p0-p1 makes with the positive x-axis.

Referenced by normalize(), normalizePositive(), and project().

## angleBetween()

double geos::algorithm::Angle::angleBetween | ( | const geom::CoordinateXY & | tip1,
|  | const geom::CoordinateXY & | tail,
|  | const geom::CoordinateXY & | tip2 )

static

Returns the unoriented smallest angle between two vectors.

The computed angle will be in the range [0, Pi).

Parameters

  tip1 | the tip of one vector
  tail | the tail of each vector
  tip2 | the tip of the other vector

Returns
  the angle between tail-tip1 and tail-tip2

## angleBetweenOriented()

double geos::algorithm::Angle::angleBetweenOriented | ( | const geom::CoordinateXY & | tip1,
|  | const geom::CoordinateXY & | tail,
|  | const geom::CoordinateXY & | tip2 )

static

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 from v1 to v2; a negative result corresponds to a clockwise rotation.

Parameters

  tip1 | the tip of v1
  tail | the tail of each vector
  tip2 | the tip of v2

Returns
  the angle between v1 and v2, relative to v1

## bisector()

double geos::algorithm::Angle::bisector | ( | const geom::CoordinateXY & | tip1,
|  | const geom::CoordinateXY & | tail,
|  | const geom::CoordinateXY & | tip2 )

static

Computes the angle of the unoriented bisector of the smallest angle between two vectors. The computed angle will be in the range (-Pi, Pi]. Collinear inputs are handled.

Parameters

  tip1 | the tip of v1
  tail | the tail of each vector
  tip2 | the tip of v2

Returns
  the angle of the bisector between v1 and v2

## diff()

double geos::algorithm::Angle::diff | ( | double | ang1,
|  | double | ang2 )

static

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] )

## getTurn()

int geos::algorithm::Angle::getTurn | ( | double | ang1,
|  | double | ang2 )

static

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.

## interiorAngle()

double geos::algorithm::Angle::interiorAngle | ( | const geom::CoordinateXY & | p0,
|  | const geom::CoordinateXY & | p1,
|  | const geom::CoordinateXY & | p2 )

static

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 ring
  p1 | the next point of the ring
  p2 | the next point of the ring

Returns
  the interior angle based at `p1`

## isAcute()

bool geos::algorithm::Angle::isAcute | ( | const geom::CoordinateXY & | p0,
|  | const geom::CoordinateXY & | p1,
|  | const geom::CoordinateXY & | p2 )

static

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 angle
  p1 | the base of the angle
  p2 | the other endpoint of the angle

## isObtuse()

bool geos::algorithm::Angle::isObtuse | ( | const geom::CoordinateXY & | p0,
|  | const geom::CoordinateXY & | p1,
|  | const geom::CoordinateXY & | p2 )

static

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 angle
  p1 | the base of the angle
  p2 | the other endpoint of the angle

## normalize()

double geos::algorithm::Angle::normalize | ( | double | angle | ) |

static

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]

References angle().

## normalizePositive()

double geos::algorithm::Angle::normalizePositive | ( | double | angle | ) |

static

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

References angle().

## project()

geom::CoordinateXY geos::algorithm::Angle::project | ( | const geom::CoordinateXY & | p,
|  | double | angle,
|  | double | dist )

static

Projects a point by a given angle and distance.

Parameters

  p | the point to project
  angle | the angle at which to project
  dist | the distance to project

Returns
  the projected point

References angle().

## sinCosSnap()

void geos::algorithm::Angle::sinCosSnap | ( | const double | ang,
|  | double & | rSin,
|  | double & | rCos )

inline static

Computes both sin and cos of an angle, snapping near-zero values to zero.

The angle does not need to be normalized. Unlike std::sin and std::cos, this method will snap near-zero values to zero for (e.g.) sin(pi) and cos(pi/2).

Parameters

  ang | the input angle (in radians)
  rSin | the result of sin(ang)
  rCos | the result of cos(ang)

## toDegrees()

double geos::algorithm::Angle::toDegrees | ( | double | radians | ) |

static

Converts from radians to degrees.

Parameters

  radians | an angle in radians

Returns
  the angle in degrees

## toRadians()

double geos::algorithm::Angle::toRadians | ( | double | angleDegrees | ) |

static

Converts from degrees to radians.

Parameters

  angleDegrees | an angle in degrees

Returns
  the angle in radians

The documentation for this class was generated from the following file:

- Angle.h