private PathStorage CombinePaths(IVertexSource a, IVertexSource b, ClipType clipType) { List <List <IntPoint> > aPolys = VertexSourceToClipperPolygons.CreatePolygons(a); List <List <IntPoint> > bPolys = VertexSourceToClipperPolygons.CreatePolygons(b); Clipper clipper = new Clipper(); clipper.AddPaths(aPolys, PolyType.ptSubject, true); clipper.AddPaths(bPolys, PolyType.ptClip, true); List <List <IntPoint> > intersectedPolys = new List <List <IntPoint> >(); clipper.Execute(clipType, intersectedPolys); PathStorage output = VertexSourceToClipperPolygons.CreatePathStorage(intersectedPolys); output.Add(0, 0, ShapePath.FlagsAndCommand.CommandStop); return(output); }
private void CreateAndRenderPathing(Graphics2D graphics2D, Polygons polygonsToPathAround, Polygons travelPolysLine) { Polygons travelPolygons = CreateTravelPath(polygonsToPathAround, travelPolysLine); PathStorage travelPath = VertexSourceToClipperPolygons.CreatePathStorage(travelPolygons); travelPath.Add(0, 0, ShapePath.FlagsAndCommand.CommandStop); graphics2D.Render(new Stroke(travelPath), pathColor); //graphics2D.Render(optomizedTravelPath, optomizedPpathColor); foreach (Polygon polygon in polygonsToPathAround) { for (int i = 0; i < polygon.Count; i++) { if (!polygon.IsVertexConcave(i)) { graphics2D.Circle(polygon[i].X, polygon[i].Y, 4, RGBA_Bytes.Green); } } } }
public static Mesh Revolve(IVertexSource source, int angleSteps = 30, double angleStart = 0, double angleEnd = MathHelper.Tau) { // convert to clipper polygons and scale so we can ensure good shapes Polygons polygons = VertexSourceToClipperPolygons.CreatePolygons(source); // ensure good winding and consistent shapes // clip against x=0 left and right // mirror left material across the origin // union mirrored left with right material // convert the data back to PathStorage PathStorage cleanedPath = VertexSourceToClipperPolygons.CreatePathStorage(polygons); Mesh mesh = new Mesh(); // check if we need to make closing faces if (angleStart != 0 || angleEnd != MathHelper.Tau) { // make a face for the start and end } // make the outside shell double angleDelta = (angleEnd - angleStart) / angleSteps; double currentAngle = 0; for (currentAngle = angleStart; currentAngle < angleEnd - angleDelta - EqualityTolerance; currentAngle += angleDelta) { AddRevolveStrip(cleanedPath, mesh, currentAngle, currentAngle + angleDelta); } AddRevolveStrip(cleanedPath, mesh, currentAngle, currentAngle + angleDelta); // TODO: get this working. mesh.CleanAndMergMesh(.0001); // return the completed mesh return(mesh); }