当前位置: 首页>>代码示例>>C#>>正文


C# Polygon.Set方法代码示例

本文整理汇总了C#中Polygon.Set方法的典型用法代码示例。如果您正苦于以下问题:C# Polygon.Set方法的具体用法?C# Polygon.Set怎么用?C# Polygon.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Polygon的用法示例。


在下文中一共展示了Polygon.Set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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 int PolygonizeTriangles(List<Triangle> triangulated, List<Polygon> polys, int polysLength)
            {
                int polyIndex = 0;

                if (triangulated.Count <= 0)
                    return 0;
                else
                {
                    int[] covered = new int[triangulated.Count];
                    for (int i = 0; i < triangulated.Count; ++i)
                    {
                        covered[i] = 0;
                        //Check here for degenerate triangles
                        if (((triangulated[i].x[0] == triangulated[i].x[1]) && (triangulated[i].y[0] == triangulated[i].y[1]))
                                                 || ((triangulated[i].x[1] == triangulated[i].x[2]) && (triangulated[i].y[1] == triangulated[i].y[2]))
                                                 || ((triangulated[i].x[0] == triangulated[i].x[2]) && (triangulated[i].y[0] == triangulated[i].y[2])))
                        {
                            covered[i] = 1;
                        }
                    }

                    bool notDone = true;
                    while (notDone)
                    {
                        int currTri = -1;
                        for (int i = 0; i < triangulated.Count; ++i)
                        {
                            if (covered[i] != 0)
                                continue;
                            currTri = i;
                            break;
                        }
                        if (currTri == -1)
                        {
                            notDone = false;
                        }
                        else
                        {
                            Polygon poly = new Polygon(triangulated[currTri]);
                            covered[currTri] = 1;
                            int index = 0;
                            for (int i = 0; i < 2*triangulated.Count; ++i, ++index)
                            {
                                while (index >= triangulated.Count) index -= triangulated.Count;
                                if (covered[index] != 0)
                                {
                                    continue;
                                }
                                Polygon newP = poly.Add(triangulated[index]);
                                if (newP == null)
                                    continue;

                                if (newP.nVertices > Polygon.maxVerticesPerPolygon)
                                {
                                    newP = null;
                                    continue;
                                }
                                if (newP.IsConvex())
                                { //Or should it be IsUsable?  Maybe re-write IsConvex to apply the angle threshold from Box2d
                                    poly.Set(newP);
                                    newP = null;
                                    covered[index] = 1;
                                }
                                else
                                    newP = null;

                            }
                            if (polyIndex < polysLength)
                            {
                                poly.MergeParallelEdges(Box2DSettings.b2_angularSlop);
                                //If identical points are present, a triangle gets
                                //borked by the MergeParallelEdges function, hence
                                //the vertex number check
                                if (poly.nVertices >= 3) polys.Add(poly);
                                //else printf("Skipping corrupt poly\n");
                            }
                            if (poly.nVertices >= 3) polyIndex++; //Must be outside (polyIndex < polysLength) test
                        }
                        //printf("MEMCHECK: %d\n",_CrtCheckMemory());
                    }
                }
                return polyIndex;
            }
开发者ID:RubisetCie,项目名称:box2c,代码行数:98,代码来源:ConvexDecomposition.cs

示例2: Triangulize

            public static int Triangulize(Polygon p, out List<Triangle> triangulated)
            {
                triangulated = null;

                if (p.nVertices < 3)
                    return 0;

                triangulated = new List<Triangle>();
                int nTri;
                if (p.IsCCW())
                {
                    //printf("It is ccw \n");
                    Polygon tempP = new Polygon();
                    tempP.Set(p);
                    ReversePolygon(tempP.x, tempP.y);
                    nTri = TriangulatePolygon(tempP.x, tempP.y, triangulated);
                    //                      ReversePolygon(p->x, p->y, p->nVertices); //reset orientation
                }
                else
                {
                    //printf("It is not ccw \n");
                    nTri = TriangulatePolygon(p.x, p.y, triangulated);
                }
                if (nTri < 1)
                {
                    //Still no luck?  Oh well...
                    return -1;
                }
                return nTri;
            }
开发者ID:RubisetCie,项目名称:box2c,代码行数:30,代码来源:ConvexDecomposition.cs


注:本文中的Polygon.Set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。