Beispiel #1
0
            //private float height = .050f;
            private LineStrip FindLargestLoop(Segment start)
            {
                //height += 0.050f;
                Vector3 normal = new Vector3 (0, 0, 1);

                Segment next = start;

                List<Segment> seen = new List<Segment>();

                while (!seen.Contains(next))
                {
                    //GL.Disable(EnableCap.Lighting);
                    //GL.LineWidth(3);
                    //GL.Begin(PrimitiveType.Lines);
                    //GL.Color3(Color.Blue);
                    //GL.Vertex3(next.a.vector.X, next.a.vector.Y, height);
                    //GL.Color3(Color.LightGreen);
                    //height += .010f;
                    //GL.Vertex3(next.b.vector.X, next.b.vector.Y, height);
                    //GL.End();
                    //GL.LineWidth(1);
                    //GL.Enable(EnableCap.Lighting);

                    seen.Add(next);
                    Segment best = null;
                    float largestAngle = 0;
                    foreach (Segment s in next.b.used_as_a)
                    {
                        float angle = Angle(-s.Normal, next.Normal, normal);
                        if (angle > largestAngle)
                        {
                            largestAngle = angle;
                            best = s;
                        }
                    }
                    if (best == null)
                    {
                        // No loops
                        return null;
                    }

                    // Destructive: remove references to this element so it's not searched again.
                    // Note: only need to remove forward links (from used_as_a).  The links from
                    // used_as_b could be cleared too, but it's not necessary for the algorithm.
                    next.b.used_as_a.Clear();
                    //next.b.used_as_b.Clear();

                    next = best;
                }
                // Remove all up to the first matched index
                int index = seen.IndexOf(next);
                seen.RemoveRange(0, index);

                LineStrip loop = new LineStrip();
                foreach (Segment seg in seen)
                {
                    loop.Append(seg.a.vector);
                }

                return loop;
            }
Beispiel #2
0
 public void AddSegment(Vector3 a, Vector3 b)
 {
     var va = FindVectorWrapper(a);
     var vb = FindVectorWrapper(b);
     var s = new Segment(){a = va, b = vb};
     segments.Add(s);
     va.used_as_a.Add(s);
     vb.used_as_b.Add(s);
 }