private static Surface SurfaceFrom4Points(Point p1, Point p2, Point p3, Point p4) { Surface surface = new Surface(); List <Curve> edges = new List <Curve>(); edges.Add(new Line(p1, p2)); edges.Add(new Line(p2, p3)); edges.Add(new Line(p3, p4)); edges.Add(new Line(p4, p1)); surface.TrimmingCurves = new Group <Curve>(CurveUtils.Join(edges)); Curve c = surface.TrimmingCurves[0]; surface.PointColumns = 2; surface.ControlPointVector = new double[4 * (surface.Dimensions + 1)]; double[] row1 = CollectionUtils.SubArray <double>(c.ControlPointVector, 0, (surface.Dimensions + 1) * 2); double[] row2 = CollectionUtils.Reverse <double>(CollectionUtils.SubArray <double>(c.ControlPointVector, (surface.Dimensions + 1) * 2, (surface.Dimensions + 1) * 2), surface.Dimensions + 1); surface.ControlPointVector = CollectionUtils.Merge <double>(row1, row2); surface.Weights = new double[] { 1, 1, 1, 1 }; surface.uKnots = new double[] { 0, 0, 1, 1 }; surface.vKnots = new double[] { 0, 0, 1, 1 }; return(surface); }
public static List <Brep> Join(List <Brep> breps) { Brep joined = null; List <Brep> result = new List <Brep>(); for (int i = 0; i < breps.Count; i++) { result.Add(breps[i]); } //Join by overlapping naked edges int counter = 0; while (counter < result.Count) { List <Curve> b1Curves = CurveUtils.Join(result[counter].GetExternalEdges()); for (int j = counter + 1; j < result.Count; j++) { if (TryJoin(result[counter], result[j], out joined)) { result[j] = joined; result.RemoveAt(counter--); break; } } } return(result); }
public static List <Curve> Split(this Curve curve, Plane p, bool keepClosed = false, double tolerance = 0.0001) { if (!curve.IsNurbForm) { curve.CreateNurbForm(); } List <Curve> unsplit = new List <Curve>() { curve }; if (p.IsSameSide(curve.ControlPointVector, tolerance)) { return(unsplit); } List <double> curveParams = new List <double>(); Intersect.PlaneCurve(p, curve, tolerance, out curveParams); List <Curve> split = curve.Split(curveParams); if (keepClosed && curve.IsClosed()) { List <Curve> lhs = new List <Curve>(); List <Curve> rhs = new List <Curve>(); for (int i = 0; i < split.Count; i++) { int[] side = p.GetSide(split[i].ControlPointVector, 0.001); int counter = 0; while (counter < side.Length && side[counter] == 0) { counter++; } if (counter < side.Length) { if (side[counter] == -1) { lhs.Add(split[i]); } else { rhs.Add(split[i]); } } } split = CurveUtils.Join(lhs); split.AddRange(CurveUtils.Join(rhs)); for (int i = 0; i < split.Count; i++) { split[i].Append(new Line(split[i].EndPoint, split[i].StartPoint)); } } return(split); }
public static Surface SurfaceFromBoundaryCurves(Group <Curve> boundaryCurves, out List <Curve> unusedCurves) { List <Curve> curves = CurveUtils.Join(boundaryCurves); Plane plane = null; Group <Curve> closedCurves = new Group <Curve>(); unusedCurves = new List <Curve>(); foreach (Curve boundary in boundaryCurves) { if (boundary.IsPlanar() && boundary.IsClosed()) { Curve xY = boundary.DuplicateCurve(); if (plane == null && xY.TryGetPlane(out plane)) { closedCurves.Add(xY); } else if (plane != null && plane.InPlane(xY.ControlPointVector, xY.Dimensions + 1, 0.001)) { closedCurves.Add(xY); } else { unusedCurves.Add(xY); } } else { unusedCurves.Add(boundary); } } if (plane != null) { Point centre = closedCurves.Bounds().Centre; Vector axis = plane.Normal; double angle = VectorUtils.VectorAngle(BH.oM.Geometry.Vector.ZAxis(), axis); Transform t1 = Geometry.Transform.Rotation(centre, axis, angle); Transform t2 = Geometry.Transform.Translation(BH.oM.Geometry.Point.Origin - centre) * t1; closedCurves.Transform(t2); Vector extents = closedCurves.Bounds().Extents; Point p1 = new Point(extents.X, -extents.Y, 0); Point p2 = new Point(extents.X, extents.Y, 0); Point p3 = new Point(-extents.X, -extents.Y, 0); Point p4 = new Point(-extents.X, extents.Y, 0); Surface surface = SurfaceFrom4Points(p1, p2, p3, p4); surface.Transform(t2.Inverse()); surface.TrimmingCurves.AddRange(closedCurves); return(surface); } return(null); }
public static bool TryJoin(Brep b1, Brep b2, out Brep result) { List <Curve> c1 = CurveUtils.Join(b1.GetExternalEdges()); List <Curve> c2 = CurveUtils.Join(b2.GetExternalEdges()); List <Curve> nakedEdges = new List <Curve>(); List <Curve> overlappedEdges = new List <Curve>(); List <Point> pts = new List <Point>(); List <Curve> updatedN = new List <Curve>(); List <Curve> updatedI = new List <Curve>(); for (int i = 0; i < c1.Count; i++) { for (int j = 0; j < c2.Count; j++) { if (Intersect.CurveCurve(c1[i], c2[j], 0.001, out pts, out overlappedEdges, out nakedEdges)) { updatedN.AddRange(nakedEdges); updatedN.AddRange(overlappedEdges); } } } if (updatedN.Count > 0) { Group <Brep> polySurface = new Group <Brep>(); if (b1 is PolySurface) { polySurface.AddRange((b1 as PolySurface).Surfaces); } else { polySurface.Add(b1); } if (b2 is PolySurface) { polySurface.AddRange((b2 as PolySurface).Surfaces); } else { polySurface.Add(b2); } result = new PolySurface(polySurface); result.GetExternalEdges().AddRange(updatedN); result.GetInternalEdges().AddRange(updatedI); return(true); } else { result = null; return(false); } }