Beispiel #1
0
        /// <summary>
        /// Create a new triangle with 3 new edge 
        /// </summary>
        /// <param name="vert1"></param>
        /// <param name="vert2"></param>
        /// <param name="vert3"></param>
        /// <param name="he1"></param>
        /// <param name="he2"></param>
        /// <param name="he3"></param>
        public static void CreateTriangle( IVertex<float> vert1, IVertex<float> vert2, IVertex<float> vert3,
            out Half_Edge he1, out Half_Edge he2, out Half_Edge he3 )
        {
            // create the new triangle
            he1 = new Half_Edge();
            he2 = new Half_Edge();
            he3 = new Half_Edge();

            // CCW test
            if ( ( ( vert2.X - vert1.X ) * ( vert3.Y - vert1.Y ) - ( vert3.X - vert1.X ) * ( vert2.Y - vert1.Y ) ) > 0 ) {
                he1.NextEdge = he2;
                he2.NextEdge = he3;
                he3.NextEdge = he1;
            } else {
                he1.NextEdge = he3;
                he3.NextEdge = he2;
                he2.NextEdge = he1;
            }

            // set the vertex
            he1.StartVertex = vert1;
            he2.StartVertex = vert2;
            he3.StartVertex = vert3;

            // set null the twin edge
            he1.TwinEdge = null;
            he2.TwinEdge = null;
            he3.TwinEdge = null;
        }
Beispiel #2
0
        /// <summary>
        /// Create a new node
        /// </summary>
        /// <param name="item"></param>
        /// <param name="before"></param>
        /// <param name="after"></param>
        public BoundaryNode( Half_Edge item, Boolean IsTheRoot = false )
        {
            // set the current item
            this.currentEdge = item;

            // set if this node is the root
            this.IsTheRoot = IsTheRoot;
        }
Beispiel #3
0
        public Face( Half_Edge HalfEnd )
        {
            // set the internal pointers
            this.HalfEnd = HalfEnd;

            // link this face to the edge
            HalfEnd.Face = this;
            HalfEnd.NextEdge.Face = this;
            HalfEnd.NextEdge.NextEdge.Face = this;

            // update the internal state
            this.Update();
        }
Beispiel #4
0
        /// <summary>
        /// Create a new triangle with 1 old edge and 2 new edge
        /// </summary>
        /// <param name="he1">The old edge</param>
        /// <param name="vert2"></param>
        /// <param name="vert3"></param>
        /// <param name="he2"></param>
        /// <param name="he3"></param>
        public static void CreateTriangle( Half_Edge he1, IVertex<float> vert2, IVertex<float> vert3,
            out Half_Edge he2, out Half_Edge he3 )
        {
            // create the new triangle
            he2 = new Half_Edge();
            he3 = new Half_Edge();

            // link the triangle
            he1.NextEdge = he2;
            he2.NextEdge = he3;
            he3.NextEdge = he1;

            // set the vertex
            he2.StartVertex = vert2;
            he3.StartVertex = vert3;
        }
Beispiel #5
0
 /// <summary>
 /// Link the half edges
 /// </summary>
 /// <param name="half_Edge"></param>
 public void LinkEdge(Half_Edge half_Edge)
 {
     // link the twin edges :P
     this.TwinEdge = half_Edge;
     half_Edge.TwinEdge = this;
 }
Beispiel #6
0
        /// <summary>
        /// Recursive correction of triangles
        /// the common edge is the edge of the other triangle
        /// </summary>
        /// <param name="CommonEdge"></param>
        /// <param name="faceTree"></param>
        public void DelaunayCorrection( Half_Edge CommonEdge, IFaceTree faceTree )
        {
            if (CommonEdge != null && this.InCircle(CommonEdge.NextEdge.NextEdge.StartVertex))
            {
                // remove the faces from the tree before to change them
                faceTree.Remove(CommonEdge.Face);
                faceTree.Remove(CommonEdge.TwinEdge.Face);

                // swap the common edge
                CommonEdge.Swap();

                // add the face again with the new parameters
                faceTree.Add(CommonEdge.Face);
                faceTree.Add(CommonEdge.TwinEdge.Face);

                // run correction for the next 2 triangles
                if(CommonEdge.StartVertex == this.StartVertex){
                    CommonEdge.DelaunayCorrection(CommonEdge.NextEdge.TwinEdge, faceTree);
                    CommonEdge.TwinEdge.NextEdge.DelaunayCorrection(CommonEdge.TwinEdge.NextEdge.NextEdge.TwinEdge, faceTree);
                }else{
                    CommonEdge.NextEdge.DelaunayCorrection(CommonEdge.NextEdge.NextEdge.TwinEdge, faceTree);
                    CommonEdge.TwinEdge.DelaunayCorrection(CommonEdge.TwinEdge.NextEdge.TwinEdge, faceTree);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Update the internal half edge and the min/max
        /// </summary>
        /// <param name="newHE"></param>
        public void Update(Half_Edge newHE)
        {
            // set the internal half edge
            HalfEnd = newHE;
            HalfEnd.Face = this;
            HalfEnd.NextEdge.Face = this;
            HalfEnd.NextEdge.NextEdge.Face = this;

            // update the min/max
            this.Update();
        }
Beispiel #8
0
        /// <summary>
        /// find the min Dist of the vert from all the edges.
        /// Return the edge that have the min dist
        /// </summary>
        /// <param name="vert"></param>
        /// <param name="minEdge"></param>
        /// <returns></returns>
        public double minDistEdge(IVertex<float> vert, out Half_Edge minEdge)
        {
            double dist1, dist2, dist3;

            // get the 3 dist from the edge
            dist1 = HalfEnd.Dist(vert);
            dist2 = HalfEnd.NextEdge.Dist(vert);
            dist3 = HalfEnd.NextEdge.NextEdge.Dist(vert);

            // find the minimum
            if (dist1 < dist2)
                if (dist1 < dist3)
                {
                    minEdge = this.HalfEnd;
                    return dist1;
                }
                else
                {
                    minEdge = this.HalfEnd.NextEdge.NextEdge;
                    return dist3;
                }
            else if (dist2 < dist3)
            {
                minEdge = this.HalfEnd.NextEdge;
                return dist2;
            }
            else
            {
                minEdge = this.HalfEnd.NextEdge.NextEdge;
                return dist3;
            }
        }