static bool checkPointToSegment(Vertex sA, Vertex sB, Vertex point)
        {
            if ((sA.Position.Y < point.Position.Y && sB.Position.Y >= point.Position.Y) ||
                (sB.Position.Y < point.Position.Y && sA.Position.Y >= point.Position.Y))
            {
                float x =
                    sA.Position.X +
                    (point.Position.Y - sA.Position.Y) /
                    (sB.Position.Y - sA.Position.Y) *
                    (sB.Position.X - sA.Position.X);

                if (x < point.Position.X)
                    return true;
            }

            return false;
        }
        public bool ContainsPoint(Vertex point)
        {
            //return true if the point to test is one of the vertices
            if (point.Equals(A) || point.Equals(B) || point.Equals(C))
                return true;

            bool oddNodes = false;

            if (checkPointToSegment(C, A, point))
                oddNodes = !oddNodes;
            if (checkPointToSegment(A, B, point))
                oddNodes = !oddNodes;
            if (checkPointToSegment(B, C, point))
                oddNodes = !oddNodes;

            return oddNodes;
        }
 public LineSegment(Vertex a, Vertex b)
 {
     A = a;
     B = b;
 }
Exemple #4
0
        private static void ValidateAdjacentVertex(Vertex vertex)
        {
            Log("Validating: {0}...", vertex);

            if (reflexVertices.Contains(vertex))
            {
                if (IsConvex(vertex))
                {
                    reflexVertices.Remove(vertex);
                    convexVertices.Add(vertex);
                    Log("Vertex: {0} now convex", vertex);
                }
                else
                {
                    Log("Vertex: {0} still reflex", vertex);
                }
            }

            if (convexVertices.Contains(vertex))
            {
                bool wasEar = earVertices.Contains(vertex);
                bool isEar = IsEar(vertex);

                if (wasEar && !isEar)
                {
                    earVertices.Remove(vertex);
                    Log("Vertex: {0} no longer ear", vertex);
                }
                else if (!wasEar && isEar)
                {
                    earVertices.AddFirst(vertex);
                    Log("Vertex: {0} now ear", vertex);
                }
                else
                {
                    Log("Vertex: {0} still ear", vertex);
                }
            }
        }
Exemple #5
0
 private static bool IsReflex(Vertex c)
 {
     return !IsConvex(c);
 }
Exemple #6
0
        private static bool IsEar(Vertex c)
        {
            Vertex p = polygonVertices[polygonVertices.IndexOf(c) - 1].Value;
            Vertex n = polygonVertices[polygonVertices.IndexOf(c) + 1].Value;

            Log("Testing vertex {0} as ear with triangle {1}, {0}, {2}...", c, p, n);

            foreach (Vertex t in reflexVertices)
            {
                if (t.Equals(p) || t.Equals(c) || t.Equals(n))
                    continue;

                if (Triangle.ContainsPoint(p, c, n, t))
                {
                    Log("\tTriangle contains vertex {0}...", t);
                    return false;
                }
            }

            return true;
        }
Exemple #7
0
        private static bool IsConvex(Vertex c)
        {
            Vertex p = polygonVertices[polygonVertices.IndexOf(c) - 1].Value;
            Vertex n = polygonVertices[polygonVertices.IndexOf(c) + 1].Value;

            Vector2 d1 = Vector2.Normalize(c.Position - p.Position);
            Vector2 d2 = Vector2.Normalize(n.Position - c.Position);
            Vector2 n2 = new Vector2(-d2.Y, d2.X);

            return (Vector2.Dot(d1, n2) <= 0f);
        }
 public static bool ContainsPoint(Vertex a, Vertex b, Vertex c, Vertex point)
 {
     return new Triangle(a, b, c).ContainsPoint(point);
 }
 public Triangle(Vertex a, Vertex b, Vertex c)
 {
     A = a;
     B = b;
     C = c;
 }
Exemple #10
0
 public bool Equals(Vertex obj)
 {
     return obj.Position.Equals(Position) && obj.Index == Index;
 }
Exemple #11
0
 public bool Equals(Vertex obj)
 {
     return(obj.Position.Equals(Position) && obj.Index == Index);
 }