C# 클래스 Project290.Physics.Common.Decomposition.EarclipDecomposer

Ported from jBox2D. Original author: ewjordan Triangulates a polygon using simple ear-clipping algorithm. Only works on simple polygons. Triangles may be degenerate, especially if you have identical points in the input to the algorithm. Check this before you use them.
파일 보기 프로젝트 열기: scastle/Solitude

공개 메소드들

메소드 설명
ConvexPartition ( Vertices vertices ) : List

Decomposes a non-convex polygon into a number of convex polygons, up to maxPolys (remaining pieces are thrown out). Each resulting polygon will have no more than Settings.MaxPolygonVertices vertices. Warning: Only works on simple polygons

ConvexPartition ( Vertices vertices, int maxPolys, float tolerance ) : List

Decomposes a non-convex polygon into a number of convex polygons, up to maxPolys (remaining pieces are thrown out). Each resulting polygon will have no more than Settings.MaxPolygonVertices vertices. Warning: Only works on simple polygons

PolygonizeTriangles ( List triangulated, int maxPolys, float tolerance ) : List

Turns a list of triangles into a list of convex polygons. Very simple method - start with a seed triangle, keep adding triangles to it until you can't add any more without making the polygon non-convex. Returns an integer telling how many polygons were created. Will fill polys array up to polysLength entries, which may be smaller or larger than the return value. Takes O(N///P) where P is the number of resultant polygons, N is triangle count. The final polygon list will not necessarily be minimal, though in practice it works fairly well.

TriangulatePolygon ( Vertices vertices ) : List

Triangulates a polygon using simple ear-clipping algorithm. Returns size of Triangle array unless the polygon can't be triangulated. This should only happen if the polygon self-intersects, though it will not _always_ return null for a bad polygon - it is the caller's responsibility to check for self-intersection, and if it doesn't, it should at least check that the return value is non-null before using. You're warned! Triangles may be degenerate, especially if you have identical points in the input to the algorithm. Check this before you use them. This is totally unoptimized, so for large polygons it should not be part of the simulation loop. Warning: Only works on simple polygons.

비공개 메소드들

메소드 설명
AddTriangle ( Triangle t, Vertices vertices ) : Vertices
IsEar ( int i, float xv, float yv, int xvLength ) : bool

Checks if vertex i is the tip of an ear in polygon defined by xv[] and yv[]. Assumes clockwise orientation of polygon...ick

Remainder ( int x, int modulus ) : int

Fix for obnoxious behavior for the % operator for negative numbers...

ResolvePinchPoint ( Vertices pin, Vertices &poutA, Vertices &poutB ) : bool

Finds and fixes "pinch points," points where two polygon vertices are at the same point. If a pinch point is found, pin is broken up into poutA and poutB and true is returned; otherwise, returns false. Mostly for internal use. O(N^2) time, which sucks...

메소드 상세

ConvexPartition() 공개 정적인 메소드

Decomposes a non-convex polygon into a number of convex polygons, up to maxPolys (remaining pieces are thrown out). Each resulting polygon will have no more than Settings.MaxPolygonVertices vertices. Warning: Only works on simple polygons
public static ConvexPartition ( Vertices vertices ) : List
vertices Vertices The vertices.
리턴 List

ConvexPartition() 공개 정적인 메소드

Decomposes a non-convex polygon into a number of convex polygons, up to maxPolys (remaining pieces are thrown out). Each resulting polygon will have no more than Settings.MaxPolygonVertices vertices. Warning: Only works on simple polygons
public static ConvexPartition ( Vertices vertices, int maxPolys, float tolerance ) : List
vertices Vertices The vertices.
maxPolys int The maximum number of polygons.
tolerance float The tolerance.
리턴 List

PolygonizeTriangles() 공개 정적인 메소드

Turns a list of triangles into a list of convex polygons. Very simple method - start with a seed triangle, keep adding triangles to it until you can't add any more without making the polygon non-convex. Returns an integer telling how many polygons were created. Will fill polys array up to polysLength entries, which may be smaller or larger than the return value. Takes O(N///P) where P is the number of resultant polygons, N is triangle count. The final polygon list will not necessarily be minimal, though in practice it works fairly well.
public static PolygonizeTriangles ( List triangulated, int maxPolys, float tolerance ) : List
triangulated List The triangulated.
maxPolys int The maximun number of polygons
tolerance float The tolerance
리턴 List

TriangulatePolygon() 공개 정적인 메소드

Triangulates a polygon using simple ear-clipping algorithm. Returns size of Triangle array unless the polygon can't be triangulated. This should only happen if the polygon self-intersects, though it will not _always_ return null for a bad polygon - it is the caller's responsibility to check for self-intersection, and if it doesn't, it should at least check that the return value is non-null before using. You're warned! Triangles may be degenerate, especially if you have identical points in the input to the algorithm. Check this before you use them. This is totally unoptimized, so for large polygons it should not be part of the simulation loop. Warning: Only works on simple polygons.
public static TriangulatePolygon ( Vertices vertices ) : List
vertices Vertices
리턴 List