Table of Contents

Class Orientation

Namespace
NetTopologySuite.Algorithm
Assembly
NetTopologySuite.dll

Functions to compute the orientation of basic geometric structures including point triplets(triangles) and rings. Orientation is a fundamental property of planar geometries (and more generally geometry on two-dimensional manifolds).

Determining triangle orientation is notoriously subject to numerical precision errors in the case of collinear or nearly collinear points. NTS uses extended-precision arithmetic to increase the robustness of the computation.
public static class Orientation
Inheritance
Orientation
Inherited Members

Methods

Index(Coordinate, Coordinate, Coordinate)

Returns the orientation index of the direction of the point q relative to a directed infinite line specified by p1->p2. The index indicates whether the point lies to the Left or Right of the line, or lies on it Collinear. The index also indicates the orientation of the triangle formed by the three points (CounterClockwise, Clockwise, or Straight )

public static OrientationIndex Index(Coordinate p1, Coordinate p2, Coordinate q)

Parameters

p1 Coordinate

The origin point of the line vector

p2 Coordinate

The final point of the line vector

q Coordinate

The point to compute the direction to

Returns

OrientationIndex

The OrientationIndex of q in regard to the vector p1->p2

ValueDescription
Collinear, Straightq is collinear with p1->p2
Clockwise, Rightq is clockwise (right) from p1->p2
CounterClockwise, Leftq is counter-clockwise (left) from p1->p2

IsCCW(CoordinateSequence)

Tests if a ring defined by a CoordinateSequence is oriented counter-clockwise.

  • The list of points is assumed to have the first and last points equal.
  • This handles coordinate lists which contain repeated points.
  • This handles rings which contain collapsed segments (in particular, along the top of the ring).
This algorithm is guaranteed to work with valid rings. It also works with "mildly invalid" rings which contain collapsed(coincident) flat segments along the top of the ring. If the ring is "more" invalid (e.g.self-crosses or touches), the computed result may not be correct.
public static bool IsCCW(CoordinateSequence ring)

Parameters

ring CoordinateSequence

A CoordinateSequences forming a ring (with first and last point identical).

Returns

bool

true if the ring is oriented counter-clockwise.

IsCCW(Coordinate[])

Tests if a ring defined by an array of Coordinates is oriented counter-clockwise.

  • The list of points is assumed to have the first and last points equal.
  • This handles coordinate lists which contain repeated points.
  • This handles rings which contain collapsed segments (in particular, along the top of the ring).
This algorithm is guaranteed to work with valid rings. It also works with "mildly invalid" rings which contain collapsed(coincident) flat segments along the top of the ring. If the ring is "more" invalid (e.g.self-crosses or touches), the computed result may not be correct.
public static bool IsCCW(Coordinate[] ring)

Parameters

ring Coordinate[]

An array of Coordinates forming a ring (with first and last point identical)

Returns

bool

true if the ring is oriented counter-clockwise.

IsCCWArea(CoordinateSequence)

Tests if a ring defined by a CoordinateSequence is oriented counter-clockwise, using the signed area of the ring.

  • The list of points is assumed to have the first and last points equal.
  • This handles coordinate lists which contain repeated points.
  • This handles rings which contain collapsed segments (in particular, along the top of the ring).
  • This handles rings which are invalid due to self-intersection
This algorithm is guaranteed to work with valid rings. For invalid rings (containing self-intersections), the algorithm determines the orientation of the largest enclosed area (including overlaps). This provides a more useful result in some situations, such as buffering.

However, this approach may be less accurate in the case of rings with almost zero area. (Note that the orientation of rings with zero area is essentially undefined, and hence non-deterministic.)
public static bool IsCCWArea(CoordinateSequence ring)

Parameters

ring CoordinateSequence

An array of Coordinates forming a ring (with first and last point identical)

Returns

bool

true if the ring is oriented counter-clockwise.

IsCCWArea(Coordinate[])

Tests if a ring defined by an array of Coordinates is oriented counter-clockwise, using the signed area of the ring.

  • The list of points is assumed to have the first and last points equal.
  • This handles coordinate lists which contain repeated points.
  • This handles rings which contain collapsed segments (in particular, along the top of the ring).
  • This handles rings which are invalid due to self-intersection
This algorithm is guaranteed to work with valid rings. For invalid rings (containing self-intersections), the algorithm determines the orientation of the largest enclosed area (including overlaps). This provides a more useful result in some situations, such as buffering.

However, this approach may be less accurate in the case of rings with almost zero area. (Note that the orientation of rings with zero area is essentially undefined, and hence non-deterministic.)
public static bool IsCCWArea(Coordinate[] ring)

Parameters

ring Coordinate[]

An array of Coordinates forming a ring (with first and last point identical)

Returns

bool

true if the ring is oriented counter-clockwise.

ReOrient(OrientationIndex)

Re-orients an orientation.

public static OrientationIndex ReOrient(OrientationIndex orientation)

Parameters

orientation OrientationIndex

The orientation

Returns

OrientationIndex