示例#1
0
 public Triangle(Node A, Node B, Node C)
 {
     Nodes[0] = A;
     Nodes[1] = B;
     Nodes[2] = C;
 }
示例#2
0
 static Node prevElement(List<Node> workingNodes, Node n)
 {
     return workingNodes[(workingNodes.IndexOf(n) - 1) == -1 ? workingNodes.Count-1 : (workingNodes.IndexOf(n) - 1)];
 }
示例#3
0
 static Node nextElement(List<Node> workingNodes, Node n)
 {
     return workingNodes[(workingNodes.IndexOf(n) + 1) == workingNodes.Count ? 0 : (workingNodes.IndexOf(n) + 1)];
 }
示例#4
0
 static bool IsPointInTriangle(Node p1, Node p2, Node p3, Node p)
 {
     double alpha = ((p2.y - p3.y) * (p.x - p3.x) + (p3.x - p2.x) * (p.y - p3.y)) /
     ((p2.y - p3.y) * (p1.x - p3.x) + (p3.x - p2.x) * (p1.y - p3.y));
     double beta = ((p3.y - p1.y) * (p.x - p3.x) + (p1.x - p3.x) * (p.y - p3.y)) /
            ((p2.y - p3.y) * (p1.x - p3.x) + (p3.x - p2.x) * (p1.y - p3.y));
     double gamma = 1.0f - alpha - beta;
     if (alpha >= 0 && beta >= 0 && gamma >= 0)
     {
         return true;
     }
     return false;
 }
示例#5
0
        static bool IsIntersecting(Node A1, Node A2, Node B1, Node B2)
        {
            // returns true if the Line segment A1A2 intersects with the line segment B1B2
            bool lineAIntersectsSegmentB =
                ((A2.y - A1.y) * B1.x + (A2.x - A1.x) * B1.y + (A1.x * A2.y - A2.x * A1.y))
              * ((A2.y - A1.y) * B2.x + (A2.x - A1.x) * B2.y + (A1.x * A2.y - A2.x * A1.y))
              < 0 ? true : false;
            bool lineBIntersectsSegmentA =
                ((B2.y - B1.y) * A1.x + (B2.x - B1.x) * A1.y + (B1.x * B2.y - B2.x * B1.y))
              * ((B2.y - B1.y) * A2.x + (B2.x - B1.x) * A2.y + (B1.x * B2.y - B2.x * B1.y))
              < 0 ? true : false;

            return lineAIntersectsSegmentB && lineBIntersectsSegmentA;
        }
示例#6
0
        static bool IsAnEar(List<Node> workingList, Node A, Node N, Node Z)
        {
            var angle = ((Math.Atan2(Z.x - N.x, Z.y - N.y) - Math.Atan2(N.x - A.x, N.y - A.y) + Math.PI * 2) % (Math.PI * 2)) - Math.PI;
            if(angle > 0) {
            //if (N.isConvex) {
                foreach (var node in workingList)
                {
                    bool temp = IsPointInTriangle(A, N, Z, node);
                    if (!(node == A || node == N || node == Z) && temp)
                    {
                        return false;
                    }
                }

            } else if(angle < 0) {
            //} else {
                return false;
            }
            return true;
        }