C# Класс Loyc.Geometry.PolygonMath

Contains useful basic polygon algorithms: hit testing, area calculation, orientation detection.
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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

Приватные методы

Метод Описание
GWN_NextLine ( System.Point p, System.Point p1, System.Point p2 ) : int

Описание методов

GetWindingNumber() публичный статический Метод

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
Результат int

IsPointInPolygon() публичный статический Метод

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
Результат bool

IsPointInPolygon() публичный статический Метод

public static IsPointInPolygon ( IEnumerator e, System.Point p ) : bool
e IEnumerator
p System.Point
Результат bool

Orientation() публичный статический Метод

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
Результат int

Orientation() публичный статический Метод

public static Orientation ( IEnumerator poly ) : int
poly IEnumerator
Результат int

PolygonArea() публичный статический Метод

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
Результат FPL16

PolygonArea() публичный статический Метод

public static PolygonArea ( IEnumerator e ) : FPL16
e IEnumerator
Результат FPL16

PolygonArea() публичный статический Метод

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
Результат FPL32

PolygonArea() публичный статический Метод

public static PolygonArea ( IEnumerator e ) : FPL32
e IEnumerator
Результат FPL32

PolygonArea() публичный статический Метод

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
Результат double

PolygonArea() публичный статический Метод

public static PolygonArea ( IEnumerator e ) : double
e IEnumerator
Результат double

PolygonArea() публичный статический Метод

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
Результат float

PolygonArea() публичный статический Метод

public static PolygonArea ( IEnumerator e ) : float
e IEnumerator
Результат float

PolygonArea() публичный статический Метод

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
Результат long

PolygonArea() публичный статический Метод

public static PolygonArea ( IEnumerator e ) : long
e IEnumerator
Результат long