Exemple #1
0
        //points = List of points making up the shapes perimeter is order
        private static IEnumerable <DgLine> ShapeSpin(List <DgPoint> points, float scale = 0.03f, bool[] printLine = null)
        {
            //used to only show some of the lines. Only one side for example.
            //Iterate through the values in the array, printing them if true.
            //If doing a triangle {true, true, false} won't print one side.
            if (printLine == null)
            {
                printLine = new[] { true }
            }
            ;
            var printLineIndex = 0;

            var lines      = new List <DgLine>();
            var pointQueue = new Queue <DgPoint>();

            //The algorithm misses the line connecting the first and last point of the perimieter, so add it.
            lines.Add(new DgLine(points[0], points[points.Count - 1]));

            foreach (var point in points)
            {
                pointQueue.Enqueue(point);
            }

            while (true)
            {
                var first  = pointQueue.Dequeue();
                var second = pointQueue.Peek();
                var line   = new DgLine(first, second);

                printLineIndex = (printLineIndex + 1) % printLine.Length;
                if (printLine[printLineIndex])
                {
                    lines.Add(line);
                }

                pointQueue.Enqueue(line.Fraction(scale));
                if (Length(line) < 1)
                {
                    break;
                }
            }

            return(lines);
        }
Exemple #2
0
 private static double Length(DgLine l)
 {
     return(Math.Sqrt((l.P1.X - l.P2.X) * (l.P1.X - l.P2.X) + (l.P1.Y - l.P2.Y) * (l.P1.Y - l.P2.Y)));
 }