예제 #1
0
        /// <summary>
        /// Triangulates the shape.
        /// </summary>
        /// <returns>The output list.</returns>
        public List<float[]> Triangulate(float[] offset, float scale = 1.0f)
        {
            var output = new List<float[]>();

            Points.Reverse();

            var context = new SweepContext();
            context.AddPoints(Points);

            // Hole edges
            foreach (Shape h in Holes)
                context.AddHole(h.Points);

            context.InitTriangulation();
            var sweep = new Sweep();
            sweep.Triangulate(context);

            var triangles = context.GetTriangles();

            foreach (Triangle tri in triangles)
            {
                //tri.ReversePointFlow();
                output.Add(((float[])tri.Points[0]).VectorScale(scale).Add(offset));
                output.Add(((float[])tri.Points[2]).VectorScale(scale).Add(offset));
                output.Add(((float[])tri.Points[1]).VectorScale(scale).Add(offset));
            }

            return output;
        }
예제 #2
0
        /// <summary>
        /// Triangulates the shape.
        /// </summary>
        /// <returns>The output list.</returns>
        public List<Triangle> Triangulate()
        {
            var context = new SweepContext();

            var distinctPoints = Points.Distinct().ToList();
            context.AddPoints(distinctPoints);

            foreach (var hole in Holes)
                context.AddHole(hole.Points);

            context.InitTriangulation();

            var sweep = new Sweep();

            sweep.Triangulate(context);

            return context.GetTriangles();
        }