Esempio n. 1
0
        // Triangulate the polygon.
        //
        // For a nice, detailed explanation of this method,
        // see Ian Garton's Web page:
        // http://www-cgrl.cs.mcgill.ca/~godfried/teaching/cg-projects/97/Ian/cutting_ears.html
        public List<Triangle> Triangulate()
        {
            // Copy the points into a scratch array.
            PointF[] pts = new PointF[Points.Length];
            Array.Copy(Points, pts, Points.Length);

            // Make a scratch polygon.
            PolygonR pgon = new PolygonR(pts);

            // Orient the polygon clockwise.
            pgon.OrientPolygonClockwise();

            // Make room for the triangles.
            List<TriangleR> triangles = new List<TriangleR>();

            // While the copy of the polygon has more than
            // three points, remove an ear.
            while (pgon.Points.Length > 3) {
                // Remove an ear from the polygon.
                pgon.RemoveEar(triangles);
            }

            // Copy the last three points into their own triangle.
            triangles.Add(new TriangleR(pgon.Points[0], pgon.Points[1], pgon.Points[2]));

            List<Triangle> endresult = new List<Triangle>();

            foreach (TriangleR triar in triangles)
                endresult.Add(new Triangle(triar.Points[0].X, triar.Points[1].X, triar.Points[2].X, triar.Points[0].Y, triar.Points[1].Y, triar.Points[2].Y));

            return endresult;
        }
        private Triangle[] CreateTrianglesR(Way w)
        {
            PolygonR p = new PolygonR(CreatePolygon(w));

            return p.Triangulate().ToArray();
        }