public static Surface ExtractSurface(Autodesk.Revit.DB.RuledFace face, IEnumerable <PolyCurve> edgeLoops) { var c0 = face.get_Curve(0).ToProtoType(); var c1 = face.get_Curve(1).ToProtoType(); return(Surface.ByLoft(new[] { c0, c1 })); }
/// <summary> /// Given some size parameters, returns a lofted surface with random bumps. /// </summary> public static Surface WobblySurface( double baseX, double baseY, double baseZ, double width, double length, double maxHeight, int uCount, int vCount) { double dx = width / (uCount - 1); double dy = length / (vCount - 1); Random rnd = new Random(); List <Curve> curves = new List <Curve>(); List <Point> pts = null; for (double y = baseY; y <= baseY + length; y += dy) { pts = new List <Point>(); for (double x = baseX; x <= baseX + width; x += dx) { pts.Add(Point.ByCoordinates(x, y, baseZ + maxHeight * rnd.NextDouble())); } curves.Add(NurbsCurve.ByPoints(pts)); } Surface surface = Surface.ByLoft(curves); return(surface); }
public static List <Curve> MorphTo(this Curve curve1, Curve curve2, int numberOfLines, int precision = 10, double offset = 0) { numberOfLines++; Surface virtualSurface = Surface.ByLoft(new List <Curve>() { curve1, curve2 }); Vector direction = virtualSurface.NormalAtParameter(0.5, 0.5); List <Curve> curves = new List <Curve>(); // Divide both curves using the precision factor Point[] pointsCurve1 = curve1.PointDivide(precision); Point[] pointsCurve2 = curve2.PointDivide(precision); // Create a Matrix for the morphed points Point[][] points = new Point[precision + 1][]; // If the Curves are in different directions, flip them. if (pointsCurve1[0].DistanceTo(pointsCurve2[pointsCurve2.Length - 1]) < pointsCurve1[0].DistanceTo(pointsCurve2[0])) { Array.Reverse(pointsCurve2); } // Draw construction lines between the two curves using the division points for (int i = 0; i < pointsCurve1.Length; i++) { Line line = Line.ByStartPointEndPoint(pointsCurve1[i], pointsCurve2[i]); // Divide the construction line into the number of curves to create // Add the divsion points to the matrix points[i] = line.PointDivide(numberOfLines); } // Create an empty Array holding the pointWeights double[] pointWeights = new double[numberOfLines]; // Flip the Matrix to create new curves from Point[][] transposedPoints = points.TransposeRowsAndColumns(); // Create Curves from the Matrix for (int i = 1; i < transposedPoints.Length - 1; i++) { NurbsCurve curve = NurbsCurve.ByControlPoints(transposedPoints[i].ToList()); Curve curveToSegment = (offset != 0) ? (Curve)curve.Translate(direction, offset) : curve; curves.Add(curveToSegment); } return(curves); }
/// <summary> /// A simple node to create a surface from four points. /// </summary> public static Surface SurfaceFrom4Points(Point point1, Point point2, Point point3, Point point4) { Line line1 = Line.ByStartPointEndPoint(point1, point2); Line line2 = Line.ByStartPointEndPoint(point3, point4); List <Curve> curves = new List <Curve> { line1, line2 }; Surface surf = Surface.ByLoft(curves); // Remember to DISPOSE geometry elements created in the node // but not returned by it! line1.Dispose(); line2.Dispose(); return(surf); }
public void TestBasicGeometry() { var p1 = Point.ByCoordinates(0, 0, 0); var p2 = Point.ByCoordinates(10, 0, 0); var p3 = Point.ByCoordinates(0, 10, 0); var p4 = Point.ByCoordinates(10, 10, 0); var l1 = Line.ByStartPointEndPoint(p1, p2); var l2 = Line.ByStartPointEndPoint(p3, p4); var crvs = new Curve[] { l1, l2 }; var surf = Surface.ByLoft(crvs); Assert.IsNotNull(surf); Console.WriteLine(surf.Area); }
public static void CanDoSimpleLoft() { var points0 = new Point[10]; var points1 = new Point[10]; for (int i = 0; i < 10; ++i) { points0[i] = Point.ByCoordinates(i, 0, 0); points1[i] = Point.ByCoordinates(i, 10, 10); } var crv0 = NurbsCurve.ByControlPoints(points0); var crv1 = NurbsCurve.ByControlPoints(points1); var srf = Surface.ByLoft(new[] { crv0, crv1 }); Assert.NotNull(srf); Console.WriteLine(srf.PointAtParameter(0.5, 0.5)); }
public static Surface SetupArcLoft() { var pt1 = Point.ByCoordinates(0, 0, 4); var pt2 = Point.ByCoordinates(1, 1, 4); var pt3 = Point.ByCoordinates(0, 4, 4); var pt4 = Point.ByCoordinates(0, 0, 0); var pt5 = Point.ByCoordinates(2, 2, 0); var pt6 = Point.ByCoordinates(0, 4, 0); var top = Arc.ByThreePoints(pt1, pt2, pt3); var bottom = Arc.ByThreePoints(pt4, pt5, pt6); var surface = Surface.ByLoft(new List <Curve>() { top, bottom }); return(surface); }
private Surface generateTabGeo(K edge, double tabOffset) { var oldgeo = new List <Geometry>(); // now offset this edge using the surface that contains the edge this tab represents var approxcenter = Unfold.Topology.Tesselation.MeshHelpers.SurfaceAsPolygonCenter(UnfoldableFace.SurfaceEntities.First()); var vectorOffset = Vector.ByTwoPoints(approxcenter, edge.Curve.PointAtParameter(.5)).Normalized(); var offsetEdge = edge.Curve.Translate(vectorOffset.Scale(tabOffset)) as Curve; var sp = offsetEdge.PointAtParameter(.2); var ep = offsetEdge.PointAtParameter(.8); var line = Line.ByStartPointEndPoint(sp, ep); var curves = new List <Curve>() { edge.Curve, line }; // this surface is the tab surface var tabSurf = Surface.ByLoft(curves); offsetEdge.Dispose(); line.Dispose(); return(tabSurf); }
public static Dictionary <string, Autodesk.DesignScript.Geometry.Surface> Create( Autodesk.DesignScript.Geometry.Surface surface, double offset, double depth) { // offset perimeter curves by the specified offset and create new surface. // makes sure there are space between outer perimeter and the amenity space List <Curve> inCrvs = surface.OffsetPerimeterCurves(offset)["insetCrvs"].ToList(); Surface inSrf = Surface.ByPatch(PolyCurve.ByJoinedCurves(inCrvs)); // get longest curve of the inSrf Curve max; List <Curve> others; Dictionary <string, dynamic> dict = inCrvs.MaximumLength(); if (dict["maxCrv"].Count < 1) { max = dict["otherCrvs"][0] as Curve; int count = dict["otherCrvs"].Count; List <Curve> rest = dict["otherCrvs"]; others = rest.GetRange(1, (count - 1)); } else { max = dict["maxCrv"][0] as Curve; others = dict["otherCrvs"]; } // get perimeter curves of input surface List <Curve> perimCrvs = surface.PerimeterCurves().ToList(); List <Curve> matchCrvs = max.FindMatchingVectorCurves(perimCrvs); // get longest curve Curve max2; Dictionary <string, dynamic> dict2 = matchCrvs.MaximumLength(); if (dict2["maxCrv"].Count < 1) { max2 = dict2["otherCrvs"][0] as Curve; } else { max2 = dict2["maxCrv"][0] as Curve; } Vector vec = max2.ByTwoCurves(max); Curve transLine = max.Translate(vec, depth) as Curve; Line extendLine = transLine.ExtendAtBothEnds(1); List <Curve> crvList = new List <Curve>() { max, extendLine }; Surface loftSrf = Surface.ByLoft(crvList); List <bool> boolLst = new List <bool>(); foreach (var crv in others) { bool b = max.DoesIntersect(crv); boolLst.Add(b); } List <Curve> intersectingCurves = others .Zip(boolLst, (name, filter) => new { name, filter, }) .Where(item => item.filter == true) .Select(item => item.name) .ToList(); List <Curve> extendCurves = new List <Curve>(); foreach (Curve crv in intersectingCurves) { var l = crv.ExtendAtBothEnds(1); extendCurves.Add(l); } List <Surface> split = loftSrf .SplitPlanarSurfaceByMultipleCurves(extendCurves) .OfType <Surface>() .ToList(); Surface amenitySurf = split.MaximumArea()["maxSrf"] as Surface; Surface remainSurf = inSrf.Split(amenitySurf)[0] as Surface; Dictionary <string, Surface> newOutput; newOutput = new Dictionary <string, Surface> { { amenitySurfaceOutputPort, amenitySurf }, { remainingSurfaceOutputPort, remainSurf } }; //Dispose redundant geometry inCrvs.ForEach(crv => crv.Dispose()); inSrf.Dispose(); max.Dispose(); perimCrvs.ForEach(crv => crv.Dispose()); matchCrvs.ForEach(crv => crv.Dispose()); max2.Dispose(); vec.Dispose(); transLine.Dispose(); extendLine.Dispose(); crvList.ForEach(crv => crv.Dispose()); loftSrf.Dispose(); intersectingCurves.ForEach(crv => crv.Dispose()); extendCurves.ForEach(crv => crv.Dispose()); return(newOutput); }
/// <summary> /// 在两条线之间生成指定数量的曲线 /// </summary> /// <param name="curve1">第一条</param> /// <param name="curve2">第二条</param> /// <param name="number">数量</param> /// <param name="accuracy">精度,如是直线和忽略</param> /// <param name="contain">是否包含起始</param> /// <returns>生成的曲线</returns> public static List <Curve> ByBetweenTwoCurves(Curve curve1, Curve curve2, int number, int accuracy = 2, bool contain = false) { List <Curve> outCurves = new List <Curve>(); int n = number; if (!contain) { n = number + 2; } double[] parameters = new double[n]; for (int i = 0; i < n; i++) { if (i == n) { parameters[i] = 1; } else { parameters[i] = i * (1.0 / (n - 1)); } } // 如果为Line if ((curve1 as Line) != null && (curve2 as Line) != null) { if (!DetermineDirection(curve1, curve2)) { curve2 = curve2.Reverse(); } var line1 = Line.ByStartPointEndPoint(curve1.StartPoint, curve2.StartPoint); var line2 = Line.ByStartPointEndPoint(curve1.EndPoint, curve2.EndPoint); List <Point> ptList1 = new List <Point>(); List <Point> ptList2 = new List <Point>(); foreach (var i in parameters) { ptList1.Add(line1.PointAtParameter(i)); ptList2.Add(line2.PointAtParameter(i)); } for (int i = 0; i < n; i++) { var crv = Line.ByStartPointEndPoint(ptList1[i], ptList2[i]); outCurves.Add(crv); } } // 如果为PolyCurve else if ((curve1 as PolyCurve) != null || (curve2 as PolyCurve) != null) { throw new Exception("暂不支持PolyCurve!"); } else { List <Curve> crossCurves = new List <Curve>() { curve1, curve2 }; Surface surface = Surface.ByLoft(crossCurves); outCurves = ByAlongSurface(surface, number, accuracy, 0); surface.Dispose(); } if (!contain) { outCurves.RemoveAt(0); outCurves.RemoveAt(outCurves.Count - 1); } return(outCurves); }