public Connection(ConvexPolyForm startPoly, EdgeIndex startEdge, ConvexPolyForm endPoly, EdgeIndex endEdge) { StartPoly = startPoly; StartEdgeIndex = startEdge; EndPoly = endPoly; EndEdgeIndex = endEdge; }
private void RenderConnections() { // Render the connections between the edges foreach (Connection connection in _connections) { Point firstStart = connection.StartPoly.Vertices[connection.StartEdgeIndex.Start]; Point firstEnd = connection.StartPoly.Vertices[connection.StartEdgeIndex.End]; float length1 = EdgeIndex.Length(firstStart, firstEnd); Point secondStart = connection.EndPoly.Vertices[connection.EndEdgeIndex.Start]; Point secondEnd = connection.EndPoly.Vertices[connection.EndEdgeIndex.End]; float length2 = EdgeIndex.Length(secondStart, secondEnd); if (length1 <= length2) { Point point = LineSegment.GetMiddle(firstStart, firstEnd); PrimitiveDrawer.DrawFilledCircle(point, 15, new Color(0, 0, 1, 1)); } else { Point point = LineSegment.GetMiddle(secondStart, secondEnd); PrimitiveDrawer.DrawFilledCircle(point, 15, new Color(0, 0, 1, 1)); } } }
internal void TryAddVert(Point mousePos) { EdgeIndex edgeIndex = GetClosestEdge(mousePos); _vertices.Insert(edgeIndex.End, mousePos); GenerateEdges(); if (IsConcave()) { _vertices.RemoveAt(edgeIndex.End); GenerateEdges(); } }
private void RenderCrossedEdges() { foreach (var tuple in _connectIntersectedEdges) { ConvexPolyForm poly = tuple.Item1; EdgeIndex edge = tuple.Item2; Point start = poly.Vertices[edge.Start]; Point end = poly.Vertices[edge.End]; GLUtil.SetColor(new Color(0, 0, 1, 1)); PrimitiveDrawer.DrawLine2d(start, end); } }
public EdgeIndex GetClosestEdge(Point p, out float minDistance) { minDistance = float.MaxValue; EdgeIndex current = new EdgeIndex(); foreach (EdgeIndex edge in _edges) { Point start = _vertices[edge.Start]; Point end = _vertices[edge.End]; float distance = (float)EdgeIndex.GetDistance(start, end, p); if (distance < minDistance) { current = edge; minDistance = distance; } } return current; }
private void FindIntersectedEdges(Point start, Point end) { foreach (ConvexPolyForm poly in _convexPolyForm) { foreach (EdgeIndex edgeIndex in poly.Edges) { Point localStart = poly.Vertices[edgeIndex.Start]; Point localEnd = poly.Vertices[edgeIndex.End]; Point collisionPoint; bool collision = EdgeIndex.Intersects(start, end, localStart, localEnd, out collisionPoint); if (collision) { _connectIntersectedEdges.Add(new Tuple <ConvexPolyForm, EdgeIndex>(poly, edgeIndex)); } } } }
public EdgeIndex GetClosestEdge(Point p, out float minDistance) { minDistance = float.MaxValue; EdgeIndex current = new EdgeIndex(); foreach (EdgeIndex edge in _edges) { Point start = _vertices[edge.Start]; Point end = _vertices[edge.End]; float distance = (float)EdgeIndex.GetDistance(start, end, p); if (distance < minDistance) { current = edge; minDistance = distance; } } return(current); }
private void RenderNormals(ConvexPolyForm poly) { GLUtil.SetColor(new Color(0, 1, 0, 1)); foreach (EdgeIndex edge in poly.Edges) { Point start = poly.Vertices[edge.Start]; Point end = poly.Vertices[edge.End]; Point middle = LineSegment.GetMiddle(start, end); Point normal = EdgeIndex.GetLineNormal(start, end); Gl.glBegin(Gl.GL_LINES); { GLUtil.DrawPointVertex(middle); GLUtil.DrawPointVertex(new Point(middle.X + (normal.X * 50), middle.Y + (normal.Y * 50))); } Gl.glEnd(); } }
public LineSegment GetShortestEdge() { Point firstStart = StartPoly.Vertices[StartEdgeIndex.Start]; Point firstEnd = StartPoly.Vertices[StartEdgeIndex.End]; float length1 = EdgeIndex.Length(firstStart, firstEnd); Point secondStart = EndPoly.Vertices[EndEdgeIndex.Start]; Point secondEnd = EndPoly.Vertices[EndEdgeIndex.End]; float length2 = EdgeIndex.Length(secondStart, secondEnd); if (length1 <= length2) { return(new LineSegment(firstStart, firstEnd)); } else { return(new LineSegment(secondStart, secondEnd)); } }
private void RenderNearestEdge(ConvexPolyForm poly) { EdgeIndex edge = poly.GetClosestEdge(_input.Mouse.Position); GLUtil.SetColor(new Color(1, 0, 0, 1)); Gl.glBegin(Gl.GL_LINE_STRIP); { GLUtil.DrawPointVertex(poly.Vertices[edge.Start]); GLUtil.DrawPointVertex(poly.Vertices[edge.End]); } Gl.glEnd(); // Render closest point Point p = EdgeIndex.GetClosestPoint(poly.Vertices[edge.Start], poly.Vertices[edge.End], _input.Mouse.Position); Gl.glBegin(Gl.GL_POINTS); { GLUtil.DrawPointVertex(p); } Gl.glEnd(); }