Beispiel #1
0
        /*
         * The chordal axis is obtained by connecting the midpoints of the internal edges.
         */
        protected Chord2D GetChordalAxis(Face2D external, List <Face2D> faces)
        {
            var t = external.Triangle;

            Vertex2D  src, dst;
            Segment2D dstEdge;

            bool e0 = ExternalSegment(t.s0);
            bool e1 = ExternalSegment(t.s1);
            bool e2 = ExternalSegment(t.s2);

            if (e0 && e1)
            {
                src     = t.s0.HasPoint(t.s1.a) ? t.s1.a : t.s1.b;
                dst     = triangulation.CheckAndAddVertex(t.s2.Midpoint());
                dstEdge = t.s2;
            }
            else if (e1 && e2)
            {
                src     = t.s1.HasPoint(t.s2.a) ? t.s2.a : t.s2.b;
                dst     = triangulation.CheckAndAddVertex(t.s0.Midpoint());
                dstEdge = t.s0;
            }
            else
            {
                src     = t.s2.HasPoint(t.s0.a) ? t.s0.a : t.s0.b;
                dst     = triangulation.CheckAndAddVertex(t.s1.Midpoint());
                dstEdge = t.s1;
            }

            var chord = new Chord2D(src, dst, external);

            chord.SetDstEdge(dstEdge);

            var connection = new Connection2D(faces);

            ChordalAxisRoutine(chord, connection);

            return(chord);
        }
Beispiel #2
0
        protected void ChordalAxisRoutine(Chord2D chord, Connection2D connection)
        {
            var origin    = chord.Face;
            var neighbors = connection.GetNeighbors(origin);

            connection.Remove(origin); // prevent overlaping to traverse

            neighbors.ForEach(neighbor => {
                var face    = neighbor.face;
                var segment = neighbor.joint;

                Vertex2D destination;
                Segment2D destinationEdge = null;

                switch (face.Type)
                {
                case Face2DType.Junction:
                    destination = triangulation.CheckAndAddVertex(face.Centroid());
                    break;

                case Face2DType.Sleeve:
                    var others = face.Triangle.ExcludeSegment(segment);
                    if (!ExternalSegment(others[0]))
                    {
                        destination     = triangulation.CheckAndAddVertex(others[0].Midpoint());
                        destinationEdge = others[0];
                    }
                    else
                    {
                        destination     = triangulation.CheckAndAddVertex(others[1].Midpoint());
                        destinationEdge = others[1];
                    }
                    break;

                // case Face2DType.Terminal:
                default:
                    destination = face.GetUncommonPoint(origin);
                    break;
                }

                Chord2D nextChord;
                if (origin.Type == Face2DType.Junction)
                {
                    var interval = new Chord2D(chord.Dst, triangulation.CheckAndAddVertex(segment.Midpoint()), origin);
                    interval.SetSrcEdge(chord.DstEdge); // maybe null
                    interval.SetDstEdge(segment);

                    nextChord = new Chord2D(interval.Dst, destination, face);
                    nextChord.SetSrcEdge(segment);
                    nextChord.SetDstEdge(destinationEdge); // null or exist

                    chord.Connect(interval);
                    interval.Connect(nextChord);
                }
                else
                {
                    nextChord = new Chord2D(chord.Dst, destination, face);
                    nextChord.SetSrcEdge(chord.DstEdge);
                    nextChord.SetDstEdge(destinationEdge); // null or exist

                    chord.Connect(nextChord);
                }

                ChordalAxisRoutine(nextChord, connection);
            });
        }