Esempio n. 1
0
 public Edge(Vertex start, Vertex end)
 {
     StartVertex = start;
     EndVertex   = end;
     Length      = StartVertex.DistanceTo(EndVertex);
     Direction   = Vector.ByTwoVertices(StartVertex, EndVertex);
 }
Esempio n. 2
0
        /// <summary>
        /// Determines if a Vertex is inside the gPolygon using Fast Winding Number method
        /// </summary>
        /// <param name="vertex"></param>
        /// <returns></returns>
        public bool ContainsVertex(Vertex vertex)
        {
            // http://geomalgorithms.com/a03-_inclusion.html
            Vertex maxVertex   = vertices.OrderByDescending(v => v.DistanceTo(vertex)).First();
            double maxDistance = vertex.DistanceTo(maxVertex) * 1.5;
            Vertex v2          = Vertex.ByCoordinates(vertex.X + maxDistance, vertex.Y, vertex.Z);
            Edge   ray         = Edge.ByStartVertexEndVertex(vertex, v2);
            int    windNumber  = 0;

            foreach (Edge edge in edges)
            {
                if (vertex.OnEdge(edge))
                {
                    return(true);
                }
                Vertex intersection = ray.Intersection(edge) as Vertex;
                if (intersection is Vertex)
                {
                    if (edge.StartVertex.Y <= vertex.Y)
                    {
                        if (edge.EndVertex.Y > vertex.Y)
                        {
                            if (IsLeft(edge, vertex) > 0)
                            {
                                ++windNumber;
                            }
                        }
                    }
                    else
                    {
                        if (edge.EndVertex.Y < vertex.Y)
                        {
                            if (IsLeft(edge, vertex) < 0)
                            {
                                --windNumber;
                            }
                        }
                    }
                }
            }

            // If windNumber is different from 0, vertex is in polygon
            return(windNumber != 0);
        }
Esempio n. 3
0
 public double DistanceTo(Vertex vertex)
 {
     return(vertex.DistanceTo(this));
 }