C# Class Loyc.Geometry.PolygonMath

Contains useful basic polygon algorithms: hit testing, area calculation, orientation detection.
Mostra file Open project: qwertie/ecsharp Class Usage Examples

Public Methods

Method Description
GetWindingNumber ( this poly, System.Point p ) : int

Counts the number of times the polygon winds around a test point, using a rightward raycasting test.

The test point is considered to be within the polygon if it lies on a top or left edge, but not on a bottom or right edge (within the precision limits of 'double' arithmetic). The test point will never be considered inside a degenerate (zero-width) area.

IsPointInPolygon ( IEnumerable poly, System.Point p ) : bool

Finds out if a point is inside the polygon using a winding test.

IsPointInPolygon ( IEnumerator e, System.Point p ) : bool
Orientation ( IEnumerable poly ) : int

Returns Math.Sign(PolygonArea(poly)): positive when clockwise and increasing Y goes upward.

A common approach to this problem is to look at the topmost point and the two points on either side. However, if one is not careful, this technique may be unable to detect the orientation in case the polygon has duplicate points, horizontal lines on top, or a degenerate top in which the top part of the polygon is zero-width (these problems can occur even if the polygon's lines do not cross one another.) That's why I chose to compute orientation based on area instead.

Orientation ( IEnumerator poly ) : int
PolygonArea ( IEnumerable polygon ) : FPL16

Computes the area of a polygon.

http://www.codeproject.com/Tips/601272/Calculating-the-area-of-a-polygon

PolygonArea ( IEnumerator e ) : FPL16
PolygonArea ( IEnumerable polygon ) : FPL32

Computes the area of a polygon.

http://www.codeproject.com/Tips/601272/Calculating-the-area-of-a-polygon

PolygonArea ( IEnumerator e ) : FPL32
PolygonArea ( IEnumerable polygon ) : double

Computes the area of a polygon.

http://www.codeproject.com/Tips/601272/Calculating-the-area-of-a-polygon

PolygonArea ( IEnumerator e ) : double
PolygonArea ( IEnumerable polygon ) : float

Computes the area of a polygon.

http://www.codeproject.com/Tips/601272/Calculating-the-area-of-a-polygon

PolygonArea ( IEnumerator e ) : float
PolygonArea ( IEnumerable polygon ) : long

Computes the area of a polygon.

http://www.codeproject.com/Tips/601272/Calculating-the-area-of-a-polygon

PolygonArea ( IEnumerator e ) : long

Private Methods

Method Description
GWN_NextLine ( System.Point p, System.Point p1, System.Point p2 ) : int

Method Details

GetWindingNumber() public static method

Counts the number of times the polygon winds around a test point, using a rightward raycasting test.
The test point is considered to be within the polygon if it lies on a top or left edge, but not on a bottom or right edge (within the precision limits of 'double' arithmetic). The test point will never be considered inside a degenerate (zero-width) area.
public static GetWindingNumber ( this poly, System.Point p ) : int
poly this
p System.Point
return int

IsPointInPolygon() public static method

Finds out if a point is inside the polygon using a winding test.
public static IsPointInPolygon ( IEnumerable poly, System.Point p ) : bool
poly IEnumerable
p System.Point
return bool

IsPointInPolygon() public static method

public static IsPointInPolygon ( IEnumerator e, System.Point p ) : bool
e IEnumerator
p System.Point
return bool

Orientation() public static method

Returns Math.Sign(PolygonArea(poly)): positive when clockwise and increasing Y goes upward.
A common approach to this problem is to look at the topmost point and the two points on either side. However, if one is not careful, this technique may be unable to detect the orientation in case the polygon has duplicate points, horizontal lines on top, or a degenerate top in which the top part of the polygon is zero-width (these problems can occur even if the polygon's lines do not cross one another.) That's why I chose to compute orientation based on area instead.
public static Orientation ( IEnumerable poly ) : int
poly IEnumerable
return int

Orientation() public static method

public static Orientation ( IEnumerator poly ) : int
poly IEnumerator
return int

PolygonArea() public static method

Computes the area of a polygon.
http://www.codeproject.com/Tips/601272/Calculating-the-area-of-a-polygon
public static PolygonArea ( IEnumerable polygon ) : FPL16
polygon IEnumerable
return FPL16

PolygonArea() public static method

public static PolygonArea ( IEnumerator e ) : FPL16
e IEnumerator
return FPL16

PolygonArea() public static method

Computes the area of a polygon.
http://www.codeproject.com/Tips/601272/Calculating-the-area-of-a-polygon
public static PolygonArea ( IEnumerable polygon ) : FPL32
polygon IEnumerable
return FPL32

PolygonArea() public static method

public static PolygonArea ( IEnumerator e ) : FPL32
e IEnumerator
return FPL32

PolygonArea() public static method

Computes the area of a polygon.
http://www.codeproject.com/Tips/601272/Calculating-the-area-of-a-polygon
public static PolygonArea ( IEnumerable polygon ) : double
polygon IEnumerable
return double

PolygonArea() public static method

public static PolygonArea ( IEnumerator e ) : double
e IEnumerator
return double

PolygonArea() public static method

Computes the area of a polygon.
http://www.codeproject.com/Tips/601272/Calculating-the-area-of-a-polygon
public static PolygonArea ( IEnumerable polygon ) : float
polygon IEnumerable
return float

PolygonArea() public static method

public static PolygonArea ( IEnumerator e ) : float
e IEnumerator
return float

PolygonArea() public static method

Computes the area of a polygon.
http://www.codeproject.com/Tips/601272/Calculating-the-area-of-a-polygon
public static PolygonArea ( IEnumerable polygon ) : long
polygon IEnumerable
return long

PolygonArea() public static method

public static PolygonArea ( IEnumerator e ) : long
e IEnumerator
return long