/// <summary> /// Radian angle from a centre to another point /// </summary> /// <param name="centre"></param> /// <param name="point"></param> /// <returns name="rad">Radians</returns> internal static double RadAngle(Point centre, Point point) { Vertex v1 = Vertex.ByCoordinates(centre.X, centre.Y, centre.Z); Vertex v2 = Vertex.ByCoordinates(point.X, point.Y, point.Z); return(Vertex.RadAngle(v1, v2)); }
/// <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); }
public static Polygon ByCenterRadiusAndSides(Vertex center, double radius, int sides) { // TODO: create polygon by plane? if (sides < 3) { throw new ArgumentOutOfRangeException("sides", "Any polygon must have at least 3 sides."); } List <Vertex> vertices = new List <Vertex>(); double angle = (Math.PI * 2) / sides; for (var i = 0; i < sides; i++) { var vertex = Vertex.ByCoordinates( (Math.Sin(i * angle) * radius) + center.X, (Math.Cos(i * angle) * radius) + center.Y, center.Z ); vertices.Add(vertex); } return(Polygon.ByVertices(vertices)); }
public static Vertex ToVertex(this Point point) { return(Vertex.ByCoordinates(point.X, point.Y, point.Z)); }
public Vertex AsVertex() { return(Vertex.ByCoordinates(this.X, this.Y, this.Z)); }