/// <summary>
        /// Adds a new vertex into the triangulation.
        /// Splits a triangle intro three, conserving the three triangle edges.
        /// </summary>
        /// <remarks>
        /// Vertex should lie within some triangle
        /// Tip: (initialize triangulation with large bounding triangle)
        /// </remarks>
        /// <param name="m_vertex"></param>
        public void AddVertex(Vector2 m_vertex)
        {
            var t = FindContainingTriangle(m_vertex);

            if (t == null)
            {
                throw new GeomException("Vertex to be added is outside triangulation");
            }

            // remove old triangle
            RemoveTriangle(t);

            // create new edges
            var e0x = new TriangleEdge(t.P0, m_vertex, null, null);
            var ex0 = new TriangleEdge(m_vertex, t.P0, e0x, null);

            e0x.Twin = ex0;
            var e1x = new TriangleEdge(t.P1, m_vertex, null, null);
            var ex1 = new TriangleEdge(m_vertex, t.P1, e1x, null);

            e1x.Twin = ex1;
            var e2x = new TriangleEdge(t.P2, m_vertex, null, null);
            var ex2 = new TriangleEdge(m_vertex, t.P2, e2x, null);

            e2x.Twin = ex2;

            // create three new triangles
            AddTriangle(new Triangle(t.E0, e1x, ex0));
            AddTriangle(new Triangle(t.E1, e2x, ex1));
            AddTriangle(new Triangle(t.E2, e0x, ex2));
        }
示例#2
0
 /// <summary>
 /// Finds edge that connects to the vertex and is not equal to given edge.
 /// </summary>
 /// <param name="a_edge"></param>
 /// <param name="a_vertex"></param>
 /// <returns></returns>
 public TriangleEdge OtherEdge(TriangleEdge a_edge, Vector2 a_vertex)
 {
     if (!Edges.Contains(a_edge) || !Vertices.Contains(a_vertex))
     {
         throw new GeomException("Edge or vertex not contained in triangle");
     }
     return(Edges.Find(e => e != a_edge && e.IsEndpoint(a_vertex)));
 }
示例#3
0
 /// <summary>
 /// Finds the edge that is not equal to given two.
 /// </summary>
 /// <param name="a_edge0"></param>
 /// <param name="a_edge1"></param>
 /// <returns></returns>
 public TriangleEdge OtherEdge(TriangleEdge a_edge0, TriangleEdge a_edge1)
 {
     if (!Edges.Contains(a_edge0) || !Edges.Contains(a_edge1))
     {
         throw new GeomException("One of the edges not contained in triangle");
     }
     return(Edges.Find(e => e != a_edge0 && e != a_edge1));
 }
示例#4
0
 /// <summary>
 /// Find the vertex that is not covered by the given triangle edge.
 /// </summary>
 /// <param name="a_edge"></param>
 /// <returns></returns>
 public Vector2?OtherVertex(TriangleEdge a_edge)
 {
     if (a_edge != E0 && a_edge != E1 && a_edge != E2)
     {
         throw new GeomException(string.Format("{0} not equal to any triangle edge of {1}", a_edge, this));
     }
     return(OtherVertex(a_edge.Point1, a_edge.Point2));
 }
示例#5
0
        public Triangle(TriangleEdge a_edge0, TriangleEdge a_edge1, TriangleEdge a_edge2)
        {
            if (a_edge0.Point2 != a_edge1.Point1 || a_edge1.Point2 != a_edge2.Point1 || a_edge2.Point2 != a_edge0.Point1)
            {
                throw new GeomException("Invalid triangle edges given: " + a_edge0 + " " + a_edge1 + " " + a_edge2);
            }

            E0 = a_edge0;
            E1 = a_edge1;
            E2 = a_edge2;

            // set the triangle pointer of the edges
            a_edge0.T = a_edge1.T = a_edge2.T = this;
        }
示例#6
0
 public TriangleEdge(Vector2 a_point1, Vector2 a_point2, TriangleEdge twin, Triangle t) : this(a_point1, a_point2)
 {
     Twin = twin;
     T    = t;
 }