private static void closeIntersect(Curve innerBounderyCrv, PointCloud startPTsLeft, List <Parkingspace> finalParkingLinesLeft, Point3d crvEnd, out Curve lineOne, out CurveIntersections intersectionsOne) { int indexOne = startPTsLeft.ClosestPoint(crvEnd); lineOne = finalParkingLinesLeft[indexOne].Curves; Vector3d vectorone = lineOne.TangentAtEnd; vectorone.Rotate(RhinoMath.ToRadians(90), new Vector3d(0, 0, 1)); Point3d movedPTone = lineOne.PointAtStart + vectorone; vectorone.Rotate(RhinoMath.ToRadians(180), new Vector3d(0, 0, 1)); Point3d movedPTTwo = lineOne.PointAtStart + vectorone; PointCloud directionPT = new PointCloud(); directionPT.Add(movedPTone); directionPT.Add(movedPTTwo); int indexdir = directionPT.ClosestPoint(crvEnd); if (indexdir == 0) { vectorone.Rotate(RhinoMath.ToRadians(180), new Vector3d(0, 0, 1)); } vectorone = Vector3d.Multiply(vectorone, 10); intersectionsOne = Intersection.CurveCurve(innerBounderyCrv, new Line(lineOne.PointAtEnd, vectorone).ToNurbsCurve(), 0.01, 0.01); }
protected override void SolveInstance(IGH_DataAccess DA) { string name = String.Empty; Profile profile = null; List <Line> lines = new List <Line>(); double angle = 0.0; Material material = null; int type = 0; DA.GetData(0, ref name); DA.GetData(1, ref profile); if (!DA.GetData(2, ref angle)) { return; } if (_useDegrees) { angle = RhinoMath.ToRadians(angle); } DA.GetData(3, ref material); DA.GetData(4, ref type); DA.GetDataList(5, lines); ProfileToElements profileToElements = new ProfileToElements(name, profile, lines, angle, material, type); DA.SetData(0, profileToElements); DA.SetDataList(1, profileToElements.Breps); }
protected override void SolveInstance(IGH_DataAccess DA) { int id = 0; RebarShape rebarShape = null; int count = 0; Curve curve = null; double angle = 0.0; DA.GetData(0, ref id); DA.GetData(1, ref rebarShape); DA.GetData(2, ref curve); DA.GetData(3, ref count); if (!DA.GetData(4, ref angle)) { return; } if (_useDegrees) { angle = RhinoMath.ToRadians(angle); } RebarGroup rebarGroup = new RebarGroup(id, new RebarSpacing(rebarShape, count, curve, angle)); DA.SetData(0, rebarGroup); DA.SetDataList(1, rebarGroup.RebarGroupMesh); DA.SetDataList(2, rebarGroup.RebarGroupCurves); }
public override void Draw() { // you need the up vector to determine the rotation axis //Vector3d up_vector = new Vector3d(0.0,0.0,1.0); // this is the same as Vector3d.ZAxis, which always returns new Vector(0.0,0.0,1.0) // rotate the earth sphere (radians,rotation_axis,rotation_origin) double base_speed = 0.1; earth.Rotate(RhinoMath.ToRadians(base_speed), Vector3d.ZAxis, origin); // add earth to document doc.Objects.AddSphere(earth); //moon speed ratio (orbit time = earth : 365.4 days, moon : 27.32days) double moon_speed = 365.4 / 27.32; // you can access to the spheres center by getting the .Center property. // rotation the moon sphere moon.Rotate(RhinoMath.ToRadians(base_speed * moon_speed), Vector3d.ZAxis, earth.Center); // add moon to document doc.Objects.AddSphere(moon); }
/// <summary> /// This procedure contains the user code. Input parameters are provided as regular arguments, /// Output parameters as ref arguments. You don't have to assign output parameters, /// they will have a default value. /// </summary> private void RunScript(Brep brep, object void0, int fate, int mode, double rot, object void1, int divX, int divY, double stepZ, int inX, int inY, ref object DucatiumPanigaleumAmamusDumSpiramus, ref object Elapsed, ref object baseBoxWire, ref object baseGrid, ref object baseColumns, ref object xStruts, ref object yStruts) { if (brep == null || !brep.IsValid) { return; } System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); BrepFace baseFace = brep.Faces.Where(x => x.IsPlanar()).ToList()[0]; Curve bound = baseFace.OuterLoop.To3dCurve(); Plane plane = Plane.WorldXY; double rotPlane = RhinoMath.ToRadians(rot); plane.Rotate(rotPlane, plane.ZAxis); Box box = new Box(plane, bound); baseBoxWire = box.ToBrep().GetWireframe(-1); GetElements(box, divX, divY, baseFace, brep, stepZ, inX, inY); baseGrid = grid; baseColumns = columns; xStruts = xConn; yStruts = yConn; sw.Stop(); Elapsed = (string.Format("Elapsed: {0}ms", sw.Elapsed.TotalMilliseconds)); }
//Surfaceを回転させ積み上げていく public void MoveSrf(int num)//pile of brick { double ang = RhinoMath.ToRadians((angle / (num - 1)) * id); bool flag2 = srf.Rotate(ang, NormalVector(), Center()); bool flag3 = srf.Rotate(ang, new Vector3d(0, 1, 0), Center()); }
public Hour(double newClockTime, double newAltitudeAngle, double newAzumithAngle) { clockTime = newClockTime; altitudeAngle = RhinoMath.ToRadians(newAltitudeAngle); azumithAngle = RhinoMath.ToRadians(newAzumithAngle); sunVector = CreateSunVector(); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Guid guid = new Guid(); Point3d loc = new Point3d(); Point3d tar = new Point3d(); double ins = 100; double angle = 90; double hot = 0.5; Color diffuse = Color.Aqua; Color spec = Color.Aqua; DA.GetData("Guid", ref guid); DA.GetData("Location", ref loc); DA.GetData("Target", ref tar); DA.GetData("Intensity", ref ins); DA.GetData("Radius", ref angle); DA.GetData("HotSpot", ref hot); DA.GetData("DiffuseColor", ref diffuse); Rhino.DocObjects.LightObject spotObj = null; foreach (Rhino.DocObjects.LightObject obj in Rhino.RhinoDoc.ActiveDoc.Lights) { if (obj.Id == guid) { spotObj = obj; break; } } if (((Param_Number)Params.Input[4]).UseDegrees) { angle = RhinoMath.ToRadians(angle); } if (angle <= 0 || angle >= Math.PI / 2) { angle = Math.PI / 4; this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Radius must be in 0-Pi/2."); } if (hot <= 0 || hot >= 1) { hot = 0.5; this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "HotSpot must be in 0-1."); } spotObj.LightGeometry.LightStyle = LightStyle.WorldSpot; spotObj.LightGeometry.Location = loc; spotObj.LightGeometry.Direction = tar - loc; spotObj.LightGeometry.Intensity = ins; spotObj.LightGeometry.SpotAngleRadians = angle; spotObj.LightGeometry.HotSpot = hot; spotObj.LightGeometry.Diffuse = diffuse; spotObj.LightGeometry.Specular = spec; Rhino.RhinoDoc.ActiveDoc.Lights.Modify(guid, spotObj.LightGeometry); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <Line> lines = new List <Line>(); List <Vector3d> vectors = new List <Vector3d>(); double angle = 0; if (!DA.GetDataList(0, lines)) { return; } if (!DA.GetDataList(1, vectors)) { return; } if (!DA.GetData(2, ref angle)) { return; } if (p.UseDegrees) { angle = RhinoMath.ToRadians(angle); } List <Line> goodline = new List <Line>(); List <Line> badline = new List <Line>(); List <int> indexgood = new List <int>(); List <int> indexbad = new List <int>(); for (int i = 0; i < lines.Count; i++) { Line li = lines[i]; for (int q = 0; q < vectors.Count; q++) { double degree = Vector3d.VectorAngle(li.Direction, vectors[q]); if (degree > Math.PI * 0.5) { degree = Math.PI - degree; } if (degree <= angle + 0.000000001) { goodline.Add(li); indexgood.Add(i); lines[i] = Line.Unset; break; } } if (lines[i] != Line.Unset) { badline.Add(lines[i]); indexbad.Add(i); } } DA.SetDataList(0, badline); DA.SetDataList(1, goodline); DA.SetDataList(2, indexbad); DA.SetDataList(3, indexgood); }
//methods public void Rotate(RhinoDoc _doc) { // unit angle in one draw execution(frame). respectively for one year double delta_angle = RhinoMath.ToRadians(365.4 / rotation_days); // rotate the sphere obj.Rotate(delta_angle, Vector3d.ZAxis, rotation_origin); // add it to the document _doc.Objects.AddSphere(obj); }
protected override void SolveInstance(IGH_DataAccess access) { Curve curve = null; string edge = null; string fill = null; if (!access.GetData(0, ref curve)) { return; } access.GetData(1, ref edge); access.GetData(2, ref fill); if (string.IsNullOrWhiteSpace(edge) && string.IsNullOrWhiteSpace(fill)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Either an edge or a fill is required."); return; } Polyline polyline; if (!curve.TryGetPolyline(out polyline)) { curve = curve.ToPolyline(0.1, RhinoMath.ToRadians(0.2), 0.01, 100); curve.TryGetPolyline(out polyline); } if (polyline == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Curve could not be converted to polyline."); return; } List <string> edges = new List <string>(); List <string> fills = new List <string>(); if (!string.IsNullOrWhiteSpace(edge)) { edges.Add(edge); } if (!string.IsNullOrWhiteSpace(fill)) { fills.Add(fill); } GdiShapeGoo goo = new GdiShapeGoo(polyline, edges, fills) { DrawFillsBeforeEdges = true }; access.SetData(0, goo); }
//methods public void Rotate() { // unit angle in one draw execution(frame). respectively for one year double delta_angle = RhinoMath.ToRadians(365.4 / rotation_days); // rotate the sphere //obj.Rotate(delta_angle,Vector3d.ZAxis,rotation_origin); // seems it has little delay... //TODO: position the obj coordinates not using Rotate(); function RhinoApp.WriteLine(Loop.frame_no.ToString()); // add it to the document //_doc.Objects.AddSphere(obj); // made function to handle this }
// <Custom additional code> Point3d adjustPlane(Curve axis, Plane plnToAdjust, Brep workEnvelope, double currentAngle, out double newAngle, out bool isValid) { double param; axis.ClosestPoint(plnToAdjust.Origin, out param); Point3d pt = axis.PointAt(param); Circle circle = new Circle(new Plane(pt, new Vector3d(axis.PointAtEnd - axis.PointAtStart)), pt, pt.DistanceTo(plnToAdjust.Origin)); Curve[] overlapCurves; Point3d[] intersectionPoints; Intersection.CurveBrep(circle.ToNurbsCurve(), workEnvelope, 0.01, out overlapCurves, out intersectionPoints); Vector3d vecA = new Vector3d(pt - plnToAdjust.Origin); Vector3d vecB = new Vector3d(pt - intersectionPoints[0]); newAngle = Vector3d.VectorAngle(vecA, vecB, new Plane(pt, new Vector3d(axis.PointAtEnd - axis.PointAtStart))); newAngle = RhinoMath.ToRadians(newAngle); newAngle = currentAngle + newAngle; double surfaceDeflector = (1000 / vecB.Z) * 300; vecB.Unitize(); Vector3d vecFinal = vecB * surfaceDeflector; if (intersectionPoints.Length < 2) { isValid = false; return(new Point3d()); } else { isValid = true; double highestZ = 0; Point3d toReturn = new Point3d(); foreach (Point3d tempPt in intersectionPoints) { double tempDist = tempPt.Z; if (tempDist > highestZ) { highestZ = tempDist; toReturn = tempPt; } } return(toReturn += vecFinal); //return intersectionPoints[1] += vecFinal; } }
/// <summary> /// Called by Rhino when the user wants to run this command. /// </summary> protected override Result RunCommand(RhinoDoc doc, RunMode mode) { ReportSampleSharedXformTable("Before transform table operations:"); var go = new GetObject(); go.SetCommandPrompt("Select objects to add random transformations"); go.SubObjectSelect = false; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } foreach (var obj_ref in go.Objects()) { var count = Rnd.Next(50, 100); var transforms = new Transform[count]; for (var i = 0; i < count; i++) { var degrees = Rnd.Next(0, 360); var radians = RhinoMath.ToRadians(degrees); transforms[i] = Transform.Rotation(radians, Point3d.Origin); } if (SampleSharedXformTable.Contains(obj_ref.ObjectId)) { SampleSharedXformTable.Update(obj_ref.ObjectId, transforms); } else { SampleSharedXformTable.Add(obj_ref.ObjectId, transforms); } } ReportSampleSharedXformTable("After transform table operations:"); return(Result.Success); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Mesh mesh = new Mesh(); double angle = Math.PI / 6; DA.GetData("Mesh", ref mesh); DA.GetData("AngleLimit", ref angle); if (((Param_Number)Params.Input[1]).UseDegrees) { angle = RhinoMath.ToRadians(angle); } mesh.FaceNormals.ComputeFaceNormals(); List <Line> meshLine = new List <Line>(); for (int i = 0; i <= mesh.TopologyEdges.Count; i++) { int[] faces = mesh.TopologyEdges.GetConnectedFaces(i); if (faces.Length == 2) { Vector3d vec0 = mesh.FaceNormals[faces[0]]; Vector3d vec1 = mesh.FaceNormals[faces[1]]; if (Vector3d.VectorAngle(vec0, vec1) > angle) { meshLine.Add(mesh.TopologyEdges.EdgeLine(i)); } } else { meshLine.Add(mesh.TopologyEdges.EdgeLine(i)); } } DA.SetDataList("Edge", meshLine); }
/// <summary> /// Generate a list of curves that show the toolpath movement. /// </summary> /// <param name="onOrigin">If true generate the toolpaths at world Origin.</param> /// <param name="lineLength">The length of the cut line to be shown.</param> /// <returns>Line[] - array of lines showing the gcode positions.</returns> public Line[] ToolpathToCurves(bool onOrigin, double lineLength = 6) { List <Line> lines = new List <Line>(); foreach (DataRow row in this.GCode.Rows) { double x = (double)row["X"]; double y = (double)row["Y"]; double z = (double)row["Z"]; double angle = (double)row["Q1="]; Transform xform = Transform.Rotation(RhinoMath.ToRadians(angle), this.cutPlane.Normal, new Point3d(x, y, z)); Point3d pt0 = new Point3d(x, y, z) + (this.cutPlane.XAxis * lineLength); Point3d pt1 = new Point3d(x, y, z) - (this.cutPlane.XAxis * lineLength); pt0.Transform(xform); pt1.Transform(xform); Line line = new Line(pt0, pt1); line.Transform(this.XformInverse); lines.Add(line); } return(lines.ToArray()); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <Line> lines = new List <Line>(); double t1 = 0; double t2 = 0; if (!DA.GetDataList(0, lines) || !DA.GetData(1, ref t1) || !DA.GetData(2, ref t2)) { return; } if (p.UseDegrees) { t1 = RhinoMath.ToRadians(t1); } ////t1 角度公差 t2 两条相邻直线间的距离公差 DataTree <Line> last = new DataTree <Line>(); DataTree <int> lastIndex = new DataTree <int>(); List <Line> restLine = new List <Line>(); List <int> restIndex = new List <int>(); List <Line> collects = new List <Line>(); List <int> indexes = new List <int>(); Line collect = Line.Unset; int count = 0; for (int i = 0; i < lines.Count; i++) { if (lines[i] == Line.Unset) { continue; } collects.Add(lines[i]); indexes.Add(i); int mem = i; bool flag = true; while (true)///找出满足ln1的线段 注意,这只是单方向 { Line ln1 = collects[collects.Count - 1]; Point3d center1 = ln1.ToNurbsCurve().PointAtNormalizedLength(0.5); ///中点 double distance = double.MaxValue; for (int q = 0; q < lines.Count; q++) /////从剩余的选择满足条件的最近线段 { if (lines[q] == Line.Unset || q == mem || q == i) { continue; } Line ln2 = lines[q]; Point3d center2 = ln2.ToNurbsCurve().PointAtNormalizedLength(0.5);///中点 if (CoLine(ln1, ln2, t1, t2) && distance > center1.DistanceTo(center2)) { collect = ln2; distance = center1.DistanceTo(center2); mem = q; } } distance = double.MaxValue; if (collect != Line.Unset)///说明上式选出了满足条件的线段 { collects.Add(collect); indexes.Add(mem); lines[mem] = Line.Unset; collect = Line.Unset; continue; } if (collects.Count > 1 && flag)/////第二次遍历 { flag = false; collects.Reverse(); indexes.Reverse(); continue; } break;////没有就退出 } if (collects.Count > 1) { last.AddRange(collects, new GH_Path(0, count)); lastIndex.AddRange(indexes, new GH_Path(0, count)); lines[i] = Line.Unset; count++; } collects.Clear(); indexes.Clear(); } for (int i = 0; i < lines.Count; i++)////剩余线段 { if (lines[i] == Line.Unset) { continue; } restLine.Add(lines[i]); restIndex.Add(i); } DA.SetDataTree(0, last); DA.SetDataTree(2, lastIndex); DA.SetDataList(1, restLine); DA.SetDataList(3, restIndex); }
// <Custom additional code> List <Plane> CreateTravelPath(WindingClass wC, WindingClass nextWC, Curve curve, Curve axis, double VecAmp, bool isBackSyntax) { List <Plane> path = new List <Plane>(); Point3d[] geoDiv; int divisionCount = 30; curve.DivideByCount(divisionCount, true, out geoDiv); //curve.DivideByLength(50, true, out geoDiv); curve.Domain = new Interval(0, 1); Point3d midPoint = axis.PointAt(0.55); for (int i = 0; i < geoDiv.Length - 1; i++) { double u; double v; wC.srf.ClosestPoint(geoDiv[i], out u, out v); Plane rpln; wC.srf.FrameAt(u, v, out rpln); double param; axis.ClosestPoint(geoDiv[i], out param); // Offset plane from surface Vector3d V = rpln.ZAxis; V.Unitize(); Vector3d vec = V * VecAmp; rpln.Origin -= vec; // If is back syntax add vector that attracts the planes towards the middle if (true) { Vector3d toMid = nextWC.basePlane.Origin - midPoint; Vector3d toMidNoZ = new Vector3d(toMid.X, toMid.Y, 0); Vector3d toMidCurrent = wC.basePlane.Origin - midPoint; Vector3d toMidNoZCurrent = new Vector3d(toMidCurrent.X, toMidCurrent.Y, 0); Vector3d localToMid = rpln.Origin - midPoint; Vector3d localToMidNoZ = new Vector3d(localToMid.X, localToMid.Y, 0); if (toMidNoZ.Length >= 1900) { if (toMidNoZCurrent.Length >= 1900 && wC.edgeIndex != nextWC.edgeIndex) { localToMidNoZ += Vector3d.ZAxis * -100; rpln.Origin -= localToMidNoZ * 0.15; } else if (wC.edgeIndex != nextWC.edgeIndex) { rpln.Origin -= localToMidNoZ * 0.05; } } else { //rpln.Origin -= toMidNoZ * 0.1; } } Plane xyPlane = Plane.WorldXY; xyPlane.Origin = rpln.Origin; double distance = wC.basePlane.Origin.DistanceTo(nextWC.basePlane.Origin); // Universal Adjustments xyPlane.Rotate(RhinoMath.ToRadians(-90), xyPlane.ZAxis, xyPlane.Origin); xyPlane.Rotate(RhinoMath.ToRadians(-180), xyPlane.YAxis, xyPlane.Origin); int extremetiesThreshold = 1500; if (nextWC.basePlane.Origin.Y > wC.basePlane.Origin.Y) { // Rotate plane so robot is pulling fiber, reduces friction xyPlane.Rotate(RhinoMath.ToRadians(-45), xyPlane.YAxis, xyPlane.Origin); // Reorient if winding at extreme ends of component if (xyPlane.Origin.Y > extremetiesThreshold) { xyPlane.Rotate(RhinoMath.ToRadians(-35), xyPlane.ZAxis, xyPlane.Origin); xyPlane.Rotate(RhinoMath.ToRadians(-25), xyPlane.XAxis, xyPlane.Origin); } else if (xyPlane.Origin.Y < -extremetiesThreshold) { xyPlane.Rotate(RhinoMath.ToRadians(35), xyPlane.ZAxis, xyPlane.Origin); } } else { // Rotate plane so robot is pulling fiber, reduces friction xyPlane.Rotate(RhinoMath.ToRadians(45), xyPlane.YAxis, xyPlane.Origin); // Reorient if winding at extreme ends of component if (xyPlane.Origin.Y < -extremetiesThreshold) { xyPlane.Rotate(RhinoMath.ToRadians(35), xyPlane.ZAxis, xyPlane.Origin); xyPlane.Rotate(RhinoMath.ToRadians(-25), xyPlane.XAxis, xyPlane.Origin); } else if (xyPlane.Origin.Y > extremetiesThreshold) { xyPlane.Rotate(RhinoMath.ToRadians(-35), xyPlane.ZAxis, xyPlane.Origin); } } // Remove first few and last few travel planes if (i < 0 || i > divisionCount - 0) { } else { path.Add(xyPlane); } } return(path); }
public static IGH_GeometricGoo BldgPartToRoof(BuildingPart bldgPart) { IGH_GeometricGoo roof = bldgPart.PartGoo; PolylineCurve pL = bldgPart.PartFootprint; ///Already at min height bldgPart.PartOsmGeo.Tags.TryGetValue("roof:shape", out string roofShape); bldgPart.PartOsmGeo.Tags.TryGetValue("height", out string heightString); double height = GetHeightDimensioned(heightString); bldgPart.PartOsmGeo.Tags.TryGetValue("min_height", out string minHeightString); double min_height = GetHeightDimensioned(minHeightString); bldgPart.PartOsmGeo.Tags.TryGetValue("roof:height", out string roofHeightString); double roofHeight = GetHeightDimensioned(roofHeightString); double facadeHeight = height - roofHeight; ///Make sure there's a minium facade height for SF Transamerica Pyramid case if (facadeHeight <= 0) { facadeHeight = 2 * DocumentTolerance(); } bldgPart.PartOsmGeo.Tags.TryGetValue("roof:orientation", out string roofOrientationString); bldgPart.PartOsmGeo.Tags.TryGetValue("roof:direction", out string roofDirectionString); double roofDirection = System.Convert.ToDouble(roofDirectionString); Vector3d roofDirectionVector = Plane.WorldXY.YAxis; roofDirectionVector.Rotate(RhinoMath.ToRadians(-roofDirection), Plane.WorldXY.ZAxis); Line[] edges = pL.ToPolyline().GetSegments(); Point3d centroid = AreaMassProperties.Compute(pL).Centroid; switch (roofShape) { case "pyramidal": centroid.Z = height; pL.TryGetPolyline(out Polyline pLPolyline); Line[] pLLines = pLPolyline.GetSegments(); List <Brep> pyramidBrepList = Brep.CreatePlanarBreps(pL, DocumentTolerance()).ToList(); if (!string.IsNullOrEmpty(roofHeightString)) { Plane facadeHeightPlane = Plane.WorldXY; facadeHeightPlane.Translate(new Vector3d(0, 0, facadeHeight)); pLPolyline.Transform(Transform.PlanarProjection(facadeHeightPlane)); ///Creating individual faces seems to work better/cleaner than lofting curves for (int i = 0; i < pLLines.Count(); i++) { Line bottomEdge = pLLines[i]; Line topEdge = bottomEdge; topEdge.Transform(Transform.PlanarProjection(facadeHeightPlane)); pyramidBrepList.Add(Brep.CreateFromCornerPoints(bottomEdge.PointAt(0), bottomEdge.PointAt(1), topEdge.PointAt(1), topEdge.PointAt(0), DocumentTolerance())); } } foreach (Line edge in pLPolyline.GetSegments()) { pyramidBrepList.Add(Brep.CreateFromCornerPoints(edge.PointAt(0), centroid, edge.PointAt(1), DocumentTolerance())); } Brep[] pyramidBrep = Brep.CreateSolid(pyramidBrepList, DocumentTolerance()); if (pyramidBrep[0].IsSolid) { roof = GH_Convert.ToGeometricGoo(pyramidBrep[0]); } break; case "skillion": Line frontEdge = new Line(); Line backEdge = new Line(); double frontAngleMin = RhinoMath.ToRadians(90); double backAngleMin = RhinoMath.ToRadians(90); foreach (Line edge in edges) { Point3d closestPt = edge.ClosestPoint(centroid, true); Vector3d perpVector = closestPt - centroid; double angleDifference = Vector3d.VectorAngle(roofDirectionVector, perpVector); if (angleDifference < frontAngleMin) { frontEdge = edge; frontAngleMin = angleDifference; } if (angleDifference > backAngleMin) { backEdge = edge; backAngleMin = angleDifference; } } Point3d backEdgeFrom = backEdge.From; backEdgeFrom.Z = height; Point3d backEdgeTo = backEdge.To; backEdgeTo.Z = height; Point3d frontEdgeFrom = frontEdge.From; frontEdgeFrom.Z = facadeHeight; Point3d frontEdgeTo = frontEdge.To; frontEdgeTo.Z = facadeHeight; List <Point3d> basePtList = new List <Point3d> { backEdge.From, backEdge.To, frontEdge.From, frontEdge.To, backEdge.From }; Polyline basePolyline = new Polyline(basePtList); List <Point3d> topPtList = new List <Point3d> { backEdgeFrom, backEdgeTo, frontEdgeFrom, frontEdgeTo, backEdgeFrom }; Polyline topPolyline = new Polyline(topPtList); ///Creating individual faces seems to work better/cleaner than lofting curves List <Brep> skillionBreps = new List <Brep>(); Line[] baseLines = basePolyline.GetSegments(); Line[] topLines = topPolyline.GetSegments(); for (int i = 0; i < baseLines.Count(); i++) { Line bottomEdge = baseLines[i]; Line topEdge = topLines[i]; skillionBreps.Add(Brep.CreateFromCornerPoints(bottomEdge.PointAt(0), bottomEdge.PointAt(1), topEdge.PointAt(1), topEdge.PointAt(0), DocumentTolerance())); } Brep baseSkillion = Brep.CreateFromCornerPoints(backEdge.From, backEdge.To, frontEdge.From, frontEdge.To, DocumentTolerance()); Brep topSkillion = Brep.CreateFromCornerPoints(backEdgeFrom, backEdgeTo, frontEdgeFrom, frontEdgeTo, DocumentTolerance()); skillionBreps.Add(baseSkillion); skillionBreps.Add(topSkillion); Brep[] skillion = Brep.CreateSolid(skillionBreps, DocumentTolerance()); if (skillion.Count() > 0) { roof = GH_Convert.ToGeometricGoo(skillion[0]); } break; case "gabled": ///TODO: Look into getting oriented bbox using front edge as orientation plane, ///extrude gable roof profile from face of bbox, trim roof geo from footprint, ///loft between footprint and trimmed roof edges and join everything. ///Need to simply polylines with colinear segments. Angle tolerance based on Notre-Dame de Paris case //pL.Simplify(CurveSimplifyOptions.All, 0, RhinoMath.ToRadians(2)).TryGetPolyline(out Polyline pLSimplified); Polyline pLSimplified = pL.ToPolyline(); pLSimplified.MergeColinearSegments(DocumentAngleTolerance() * 5, true); Line[] edgesSimplified = pLSimplified.GetSegments(); if (edgesSimplified.Count() != 4) { break; } Line ridge = new Line(); Line eaveOne = new Line(); Line eaveTwo = new Line(); Polyline topGablePolyline = new Polyline(); List <Brep> gableBreps = new List <Brep>(); if ((edgesSimplified[0].Length > edgesSimplified[1].Length && roofOrientationString != "across") || ((edgesSimplified[0].Length < edgesSimplified[1].Length && roofOrientationString == "across"))) { ridge = new Line(edgesSimplified[3].PointAt(0.5), edgesSimplified[1].PointAt(0.5)); ridge.FromZ = height; ridge.ToZ = height; eaveOne = edgesSimplified[0]; eaveOne.FromZ = facadeHeight; eaveOne.ToZ = facadeHeight; eaveTwo = edgesSimplified[2]; eaveTwo.Flip(); eaveTwo.FromZ = facadeHeight; eaveTwo.ToZ = facadeHeight; topGablePolyline = new Polyline { eaveOne.From, eaveOne.To, ridge.To, eaveTwo.To, eaveTwo.From, ridge.From, eaveOne.From }; Brep[] gableRoof = Brep.CreateFromLoft(new List <Curve> { eaveOne.ToNurbsCurve(), ridge.ToNurbsCurve(), eaveTwo.ToNurbsCurve() }, Point3d.Unset, Point3d.Unset, LoftType.Straight, false); gableRoof[0].Faces.SplitKinkyFaces(); gableBreps.Add(gableRoof[0]); } if ((edgesSimplified[0].Length > edgesSimplified[1].Length && roofOrientationString == "across") || (edgesSimplified[0].Length < edgesSimplified[1].Length && roofOrientationString != "across")) { ridge = new Line(edgesSimplified[0].PointAt(0.5), edgesSimplified[2].PointAt(0.5)); ridge.FromZ = height; ridge.ToZ = height; eaveOne = edgesSimplified[1]; eaveOne.FromZ = facadeHeight; eaveOne.ToZ = facadeHeight; eaveTwo = edgesSimplified[3]; eaveTwo.Flip(); eaveTwo.FromZ = facadeHeight; eaveTwo.ToZ = facadeHeight; topGablePolyline = new Polyline { eaveTwo.From, ridge.From, eaveOne.From, eaveOne.To, ridge.To, eaveTwo.To, eaveTwo.From }; Brep[] gableRoof = Brep.CreateFromLoft(new List <Curve> { eaveOne.ToNurbsCurve(), ridge.ToNurbsCurve(), eaveTwo.ToNurbsCurve() }, Point3d.Unset, Point3d.Unset, LoftType.Straight, false); gableRoof[0].Faces.SplitKinkyFaces(); gableBreps.Add(gableRoof[0]); } Brep[] gablewalls = Brep.CreateFromLoft(new List <Curve> { pLSimplified.ToPolylineCurve(), topGablePolyline.ToPolylineCurve() }, Point3d.Unset, Point3d.Unset, LoftType.Straight, false); gablewalls[0].Faces.SplitKinkyFaces(); gablewalls[0].MergeCoplanarFaces(DocumentTolerance()); gableBreps.Add(gablewalls[0]); Brep baseGable = Brep.CreateFromCornerPoints(edgesSimplified[0].From, edgesSimplified[0].To, edgesSimplified[2].From, edgesSimplified[2].To, DocumentTolerance()); gableBreps.Add(baseGable); Brep[] gable = Brep.JoinBreps(gableBreps, DocumentTolerance()); if (gable[0].IsValid) { roof = GH_Convert.ToGeometricGoo(gable[0]); } break; default: break; } return(roof); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <Point3d> points = new List <Point3d>(); Point3d point0 = new Point3d(); Point3d point1 = new Point3d(); double tolerance = 0; if (!DA.GetDataList(0, points)) { return; } if (!DA.GetData(1, ref point0)) { return; } if (!DA.GetData(2, ref point1)) { return; } if (!DA.GetData(3, ref tolerance)) { return; } Vector3d vc2 = Point3d.Subtract(point1, point0); if (p.UseDegrees) { tolerance = RhinoMath.ToRadians(tolerance); } ///////////////////////////////////////////////////////// List <int> mems = new List <int>(); List <Point3d> pty = new List <Point3d>(); bool flag = true;///终止循环 pty.Add(point0); pty.Add(point1); for (int i = 0; i < 2; i++)///用户输入点的序号 { for (int j = 0; j < points.Count; j++) { if (points[j] == pty[i]) { mems.Add(j); break; } } } #region while (flag)////////////////////该循环每循环一次,则找出最近的满足条件的一个点直到找完为止 { double max = double.MaxValue; Point3d getPt = Point3d.Unset; int index = int.MaxValue; for (int i = 0; i < points.Count; i++) { if (pty.Contains(points[i])) { continue; } Vector3d test = Point3d.Subtract(points[i], pty[pty.Count - 1]); double angle = Vector3d.VectorAngle(test, vc2); double dist = points[i].DistanceTo(pty[pty.Count - 1]); if (angle <= tolerance && max > dist) { getPt = points[i]; max = dist; index = i; } } if (getPt != Point3d.Unset) { vc2 = Point3d.Subtract(getPt, pty[pty.Count - 1]); pty.Add(getPt); mems.Add(index); } else { flag = false; } } #endregion ; DA.SetDataList(0, pty); DA.SetDataList(1, mems); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <Curve> curves = new List <Curve>(); List <Curve> c = new List <Curve>(); double angle = 0; if (!DA.GetDataList(0, curves)) { return; } if (!DA.GetDataList(1, c)) { return; } if (!DA.GetData(2, ref angle)) { return; } if (p.UseDegrees) { angle = RhinoMath.ToRadians(angle); } ////////////////////////////////////////////////////////// List <Curve> collect = new List <Curve>(); List <int> index = new List <int>(); bool flag1 = false; bool flag2 = false; Curve c1 = null; List <Curve> same = new List <Curve>(); List <int> sameindex = chongfu(curves, c, out same);////删除与指定曲线重合部分后的源曲线 for (int k = 0; k < c.Count; k++) { c1 = c[k]; while (true) { for (int q = 0; q < curves.Count; q++) { flag1 = false; Vector3d v1 = Point3d.Subtract(c1.PointAtEnd, c1.PointAtStart); if (curves[q] == null) { continue; } Curve c2 = curves[q]; Vector3d v2 = Point3d.Subtract(c2.PointAtEnd, c2.PointAtStart); if (Rhino.Geometry.Intersect.Intersection.CurveCurve(c1, c2, 0, 0).Count == 1 && zhefan(c1, c2))///有一个交点 { double ag = Vector3d.VectorAngle(v1, v2); if (ag > Math.PI * 0.5) { ag = Math.PI - ag; } if (ag <= angle)////角度满足要求 { index.Add(q); collect.Add(curves[q]); c1 = collect[collect.Count - 1]; curves[q] = null; flag1 = true; break; } } } if (flag1)////如果有满足情况的曲线,则继续执行上一步操作 { continue; } //////////////////////////////////////////////////////////////////先判断第一个方向所有满足条件的线 ////////////////////////////////////////////////////////////////// if (!flag2) { c1 = c[k]; flag1 = false; flag2 = true; continue; } if (collect.Count == 0)/////如果没有匹配的曲线 { flag2 = false; flag1 = false; break; } flag2 = false; flag1 = false; break; } } collect.AddRange(same); index.AddRange(sameindex); DA.SetDataList(0, collect); DA.SetDataList(1, index); }
// <Custom additional code> Plane AdjustAttackAngle(WindingClass wp) { Vector3d tangent = wp.edgeCurve.TangentAt(wp.edgeParam); Plane tempPln; wp.edgeCurve.FrameAt(wp.edgeParam, out tempPln); Vector3d perpVector = Vector3d.CrossProduct(tangent, tempPln.YAxis); Plane npln = new Plane(wp.basePlane.Origin, perpVector, tangent); if (wp.edgeIndex == 1) { npln.Rotate(RhinoMath.ToRadians(180), npln.ZAxis); if (wp.edgeParam > 0.5) { npln.Rotate(RhinoMath.ToRadians(-105), npln.YAxis); npln.Rotate(RhinoMath.ToRadians(-90), npln.ZAxis); npln.Rotate(RhinoMath.ToRadians(-70), npln.XAxis); } else { npln.Rotate(RhinoMath.ToRadians(-105), npln.YAxis); npln.Rotate(RhinoMath.ToRadians(-90), npln.ZAxis); npln.Rotate(RhinoMath.ToRadians(-70), npln.XAxis); npln.Rotate(RhinoMath.ToRadians(60), npln.ZAxis); } } else if (wp.edgeIndex == 3) { npln = new Plane(wp.basePlane); npln.Rotate(RhinoMath.ToRadians(180), npln.XAxis); npln.Rotate(wp.edgeParam > 0.5 ? RhinoMath.ToRadians(50) : RhinoMath.ToRadians(70), npln.ZAxis); } else if (wp.edgeIndex == 2) { npln.Rotate(RhinoMath.ToRadians(90), npln.ZAxis); npln.Rotate(RhinoMath.ToRadians(180), npln.YAxis); npln.Rotate(RhinoMath.ToRadians(-80), npln.XAxis); if (wp.edgeParam < 0.25) { npln.Rotate(RhinoMath.ToRadians(-60), npln.ZAxis); } else if (wp.edgeParam < 0.5) { npln.Rotate(RhinoMath.ToRadians(-25), npln.ZAxis); } else if (wp.edgeParam > 0.5) { npln.Rotate(RhinoMath.ToRadians(35), npln.ZAxis); //npln.Rotate(RhinoMath.ToRadians(15), npln.XAxis); } //npln.Rotate(wp.edgeParam > 0.5 ? RhinoMath.ToRadians(65) : RhinoMath.ToRadians(-15), npln.ZAxis); } else if (wp.edgeIndex == 0) { npln.Rotate(RhinoMath.ToRadians(90), npln.ZAxis); npln.Rotate(RhinoMath.ToRadians(-90), npln.XAxis); npln.Rotate(wp.edgeParam > 0.5 ? RhinoMath.ToRadians(-25) : RhinoMath.ToRadians(25), npln.ZAxis); } // Check for vertical pins and reorient List <int> verticalPinsIds = new List <int>() { 2, 6, 10, 14, 18, 22, 26, 30, 34, 38 }; if (wp.edgeIndex == 0) { bool isInList = verticalPinsIds.IndexOf(wp.pinIndex) != -1; if (isInList) { //npln.Rotate(RhinoMath.ToRadians(-110), npln.XAxis); //npln.Rotate(RhinoMath.ToRadians(180), npln.ZAxis); //if (wp.edgeParam < 0.3) //{ // npln.Rotate(RhinoMath.ToRadians(-45), npln.ZAxis); // npln.Rotate(RhinoMath.ToRadians(-40), npln.YAxis); //} //else if (wp.edgeParam > 0.7) //{ // npln.Rotate(RhinoMath.ToRadians(45), npln.ZAxis); // npln.Rotate(RhinoMath.ToRadians(-25), npln.XAxis); // npln.Rotate(RhinoMath.ToRadians(35), npln.YAxis); // npln.Rotate(RhinoMath.ToRadians(45), npln.ZAxis); //} //else //{ // npln.Rotate(RhinoMath.ToRadians(45), npln.ZAxis); // npln.Rotate(RhinoMath.ToRadians(90), npln.YAxis); // //npln.Rotate(RhinoMath.ToRadians(30), npln.XAxis); // npln.Rotate(RhinoMath.ToRadians(45), npln.ZAxis); //} wp.isVertical = true; } } else if (wp.edgeIndex == 2) { bool isInList = verticalPinsIds.IndexOf(wp.pinIndex) != -1; if (isInList) { //npln.Rotate(RhinoMath.ToRadians(270), npln.YAxis); //npln.Rotate(RhinoMath.ToRadians(-90), npln.ZAxis); //if (wp.edgeParam < 0.3) //{ // npln.Rotate(RhinoMath.ToRadians(90), npln.YAxis); // npln.Rotate(RhinoMath.ToRadians(-20), npln.ZAxis); // npln.Rotate(RhinoMath.ToRadians(-40), npln.XAxis); //} //else if (wp.edgeParam > 0.7) //{ // npln.Rotate(RhinoMath.ToRadians(40), npln.ZAxis); // npln.Rotate(RhinoMath.ToRadians(25), npln.YAxis); // npln.Rotate(RhinoMath.ToRadians(-25), npln.XAxis); //} //else //{ // npln.Rotate(RhinoMath.ToRadians(-70), npln.XAxis); // npln.Rotate(RhinoMath.ToRadians(45), npln.ZAxis); //} wp.isVertical = true; } } return(npln); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <Curve> polylines = new List <Curve>(); double tolerance1 = 0; double tolerance2 = 0; if (!DA.GetDataList(0, polylines)) { return; } if (!DA.GetData(1, ref tolerance1)) { return; } if (!DA.GetData(2, ref tolerance2)) { return; } if (p.UseDegrees) { tolerance2 = RhinoMath.ToRadians(tolerance2); } List <Polyline> x = new List <Polyline>(); List <string> wrong = new List <string>(); for (int i = 0; i < polylines.Count; i++) { Polyline pl = null; if (polylines[i].TryGetPolyline(out pl)) { x.Add(pl); } else { string mm = "序号为" + i + "的曲线不是多段线"; wrong.Add(mm); } } double t1 = tolerance1; double t2 = tolerance2; DataTree <double> length = new DataTree <double>(); DataTree <double> angle = new DataTree <double>(); int num = 0; for (int i = 0; i < x.Count; i++) { angle.AddRange(Angles(x[i]), new GH_Path(0, num)); Line[] lines = x[i].GetSegments(); for (int j = 0; j < lines.Length; j++) { length.Add(lines[j].Length, new GH_Path(0, num)); } num++; } ///////////////////////////////////////////////////////////////// DataTree <Polyline> last = new DataTree <Polyline>(); DataTree <int> index = new DataTree <int>(); num = 0; for (int i = 0; i < x.Count; i++) { if (x[i] == null) { continue; } last.Add(x[i], new GH_Path(0, DA.Iteration, num)); index.Add(i, new GH_Path(0, DA.Iteration, num)); for (int j = 0; j < x.Count; j++) { if (x[j] == null || i == j || x[i].SegmentCount != x[j].SegmentCount) { continue; } if (Test(length.Branch(i), length.Branch(j), t1) && Test(angle.Branch(i), angle.Branch(j), t2)) { last.Add(x[j], new GH_Path(0, DA.Iteration, num)); index.Add(j, new GH_Path(0, DA.Iteration, num)); x[j] = null; } } x[i] = null; num++; } DA.SetDataTree(0, last); DA.SetDataTree(1, index); DA.SetDataList(2, wrong); }
protected override void PostDrawObjects(DrawEventArgs e) { var points = new[] { new Point3d(2, 2, 0), new Point3d(2, -6, 0), new Point3d(5, -6, 0), new Point3d(5, 2, 0) }; e.Display.DrawPolygon(points, Color.Black, false); var fill = Color.FromArgb(250, Color.White); var center = new Point3d(2, 2, 0); var off_x = new Point3d(3, 2, 0); var off_y = new Point3d(2, 3, 0); var radius = 3; e.Display.DrawPoint(center, PointStyle.RoundControlPoint, Color.Black, fill, radius, 1, 0, 0, true, true); var world_to_screen = e.Viewport.GetTransform(CoordinateSystem.World, CoordinateSystem.Screen); var center_screen = center; center_screen.Transform(world_to_screen); var off_screen = off_x; off_screen.Transform(world_to_screen); var xaxis = new Vector3d(off_screen.X - center_screen.X, off_screen.Y - center_screen.Y, 0); var angle = Vector3d.VectorAngle(Vector3d.XAxis, xaxis); if (xaxis.Y > 0) { angle = -angle; } e.Display.DrawPoint(center, PointStyle.ArrowTail, Color.Black, fill, 6, 1, 3, (float)angle, true, true); e.Display.DrawPoint(center, PointStyle.ArrowTail, Color.Black, fill, 6, 1, 3, (float)(angle + RhinoMath.ToRadians(180)), true, true); off_screen = off_y; off_screen.Transform(world_to_screen); var yaxis = new Vector3d(off_screen.X - center_screen.X, off_screen.Y - center_screen.Y, 0); angle = Vector3d.VectorAngle(Vector3d.YAxis, yaxis); if (yaxis.X < 0) { angle = -angle; } e.Display.DrawPoint(center, PointStyle.ArrowTail, Color.Black, fill, 6, 1, 3, (float)(angle + RhinoMath.ToRadians(90)), true, true); e.Display.DrawPoint(center, PointStyle.ArrowTail, Color.Black, fill, 6, 1, 3, (float)(angle + RhinoMath.ToRadians(270)), true, true); center = new Point3d(5, -2, 0); e.Display.DrawPoint(center, PointStyle.RoundControlPoint, Color.Black, fill, radius, 1, 0, 0, true, true); center_screen = center; center_screen.Transform(world_to_screen); off_screen = center; off_screen.X += 1; off_screen.Transform(world_to_screen); xaxis = new Vector3d(off_screen.X - center_screen.X, off_screen.Y - center_screen.Y, 0); angle = Vector3d.VectorAngle(Vector3d.XAxis, xaxis); if (xaxis.Y > 0) { angle = -angle; } e.Display.DrawPoint(center, PointStyle.ArrowTail, Color.Black, fill, 6, 1, 3, (float)angle, true, true); e.Display.DrawPoint(center, PointStyle.ArrowTail, Color.Black, fill, 6, 1, 3, (float)(angle + RhinoMath.ToRadians(180)), true, true); e.Display.DrawPoint(points[1], PointStyle.Pin, Color.Black, Color.PeachPuff, 15, 1, 5, 0, true, true); base.PostDrawObjects(e); }
public override bool Construct(bool append = false) { if (!append) { foreach (var part in Parts) { part.Geometry.Clear(); } } double added = ExtraLength; var obeam = (Over.Element as BeamElement).Beam; var ubeam = (Under.Element as BeamElement).Beam; var oPlane = obeam.GetPlane(Over.Parameter); var uPlane = ubeam.GetPlane(Under.Parameter); // Calculate offset for backcut angle double tan = Math.Tan(RhinoMath.ToRadians(Math.Max(1.0, TaperAngle))); double addedTan = added * tan; if (DepthOverride == 0.0) DepthOverride = obeam.Height; double TaperOffset = DepthOverride * 0.5 * tan; uPlane = UnifyPlanes(oPlane, uPlane); var xaxis = oPlane.ZAxis; var yaxis = uPlane.ZAxis; var zaxis = Vector3d.CrossProduct(xaxis, yaxis); zaxis.Unitize(); // Create centre plane var plane = new Plane((oPlane.Origin + uPlane.Origin) / 2, zaxis); var planeProj = plane.ProjectAlongVector(zaxis); // Create side planes for Over var oPlanes = new Plane[2]; oPlanes[0] = new Plane(oPlane.Origin - oPlane.XAxis * obeam.Width * 0.5, oPlane.ZAxis, oPlane.YAxis); oPlanes[1] = new Plane(oPlane.Origin + oPlane.XAxis * obeam.Width * 0.5, -oPlane.ZAxis, oPlane.YAxis); // Create side planes for Under var uPlanes = new Plane[2]; uPlanes[0] = new Plane(uPlane.Origin - uPlane.XAxis * ubeam.Width * 0.5, uPlane.ZAxis, uPlane.YAxis); uPlanes[1] = new Plane(uPlane.Origin + uPlane.XAxis * ubeam.Width * 0.5, -uPlane.ZAxis, uPlane.YAxis); var corners = new Point3d[4]; Rhino.Geometry.Intersect.Intersection.PlanePlanePlane(plane, oPlanes[0], uPlanes[0], out corners[0]); Rhino.Geometry.Intersect.Intersection.PlanePlanePlane(plane, oPlanes[0], uPlanes[1], out corners[1]); Rhino.Geometry.Intersect.Intersection.PlanePlanePlane(plane, oPlanes[1], uPlanes[1], out corners[2]); Rhino.Geometry.Intersect.Intersection.PlanePlanePlane(plane, oPlanes[1], uPlanes[0], out corners[3]); var offsetCorners = new Point3d[3]; offsetCorners[0] = corners[0] - yaxis * TaperOffset; offsetCorners[1] = corners[1] - yaxis * TaperOffset - xaxis * TaperOffset; offsetCorners[2] = corners[2] - xaxis * TaperOffset; var topCorners = new Point3d[4]; topCorners[0] = corners[0] - zaxis * (obeam.Height * 0.5 + added) + yaxis * addedTan; topCorners[1] = corners[1] - zaxis * (obeam.Height * 0.5 + added) + yaxis * addedTan + xaxis * addedTan; topCorners[2] = corners[2] - zaxis * (obeam.Height * 0.5 + added) + xaxis * addedTan; topCorners[3] = corners[3] - zaxis * (obeam.Height * 0.5 + added); var btmCorners = new Point3d[4]; btmCorners[0] = corners[0] + zaxis * (obeam.Height * 0.5 + added) + yaxis * addedTan; btmCorners[1] = corners[1] + zaxis * (obeam.Height * 0.5 + added) + yaxis * addedTan + xaxis * addedTan; btmCorners[2] = corners[2] + zaxis * (obeam.Height * 0.5 + added) + xaxis * addedTan; btmCorners[3] = corners[3] + zaxis * (obeam.Height * 0.5 + added); #if DEBUG debug.Add(corners[0]); debug.Add(corners[1]); debug.Add(corners[2]); debug.Add(corners[3]); debug.Add(offsetCorners[0]); debug.Add(offsetCorners[1]); debug.Add(offsetCorners[2]); debug.Add(topCorners[0]); debug.Add(topCorners[1]); debug.Add(topCorners[2]); debug.Add(topCorners[3]); debug.Add(btmCorners[0]); debug.Add(btmCorners[1]); debug.Add(btmCorners[2]); debug.Add(btmCorners[3]); #endif var overSrf = new Brep[6]; overSrf[0] = Brep.CreateFromCornerPoints(offsetCorners[0], offsetCorners[1], offsetCorners[2] - yaxis * added, corners[3] - yaxis * added, 0.01); overSrf[1] = Brep.CreateFromCornerPoints(offsetCorners[0], btmCorners[0], btmCorners[1], offsetCorners[1], 0.01); overSrf[2] = Brep.CreateFromCornerPoints(offsetCorners[1], topCorners[1], topCorners[2] - yaxis * added, offsetCorners[2] - yaxis * added, 0.01); overSrf[3] = Brep.CreateFromCornerPoints(corners[3] - yaxis * added, topCorners[3] - yaxis * added, topCorners[0], offsetCorners[0], 0.01); overSrf[4] = Brep.CreateFromCornerPoints(topCorners[0], offsetCorners[0], btmCorners[0], 0.01); overSrf[5] = Brep.CreateFromCornerPoints(topCorners[1], offsetCorners[1], btmCorners[1], 0.01); Over.Geometry.AddRange(Brep.JoinBreps(overSrf, 0.01)); Brep brepOver = Over.Geometry[0]; brepOver.MergeCoplanarFaces(0.01); /* UNDER */ var underSrf = new Brep[6]; underSrf[0] = Brep.CreateFromCornerPoints(offsetCorners[0] - xaxis * added, offsetCorners[1], offsetCorners[2], corners[3] - xaxis * added, 0.01); underSrf[1] = Brep.CreateFromCornerPoints(offsetCorners[0] - xaxis * added, btmCorners[0] - xaxis * added, btmCorners[1], offsetCorners[1], 0.01); underSrf[2] = Brep.CreateFromCornerPoints(offsetCorners[1], topCorners[1], topCorners[2], offsetCorners[2], 0.01); underSrf[3] = Brep.CreateFromCornerPoints(offsetCorners[2], btmCorners[2], btmCorners[3] - xaxis * added, corners[3] - xaxis * added, 0.01); underSrf[4] = Brep.CreateFromCornerPoints(topCorners[2], offsetCorners[2], btmCorners[2], 0.01); underSrf[5] = Brep.CreateFromCornerPoints(topCorners[1], offsetCorners[1], btmCorners[1], 0.01); Under.Geometry.AddRange(Brep.JoinBreps(underSrf, 0.01)); Brep brepUnder = Under.Geometry[0]; brepUnder.MergeCoplanarFaces(0.01); return true; }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <Curve> curves = new List <Curve>(); double angle = 0; if (!DA.GetDataList(0, curves)) { return; } if (!DA.GetData(1, ref angle)) { return; } if (p.UseDegrees)///设置的是角度则转换为弧度 { angle = RhinoMath.ToRadians(angle); } DataTree <Curve> last = new DataTree <Curve>(); DataTree <int> indexes = new DataTree <int>(); List <Curve> collect = new List <Curve>(); List <int> index = new List <int>(); int mem = 0; int branch = DA.Iteration; bool flag1 = false; bool flag2 = false; bool flag3 = true; Curve c1 = null; for (int i = 0; i < curves.Count; i++) { if (curves[i] == null) { continue; } if (!flag1) { c1 = curves[i]; } if (flag3) { collect.Add(curves[i]); index.Add(i); } flag1 = false; Vector3d v1 = Point3d.Subtract(c1.PointAtEnd, c1.PointAtStart); for (int q = 0; q < curves.Count; q++) { if (curves[q] == null || i == q) { continue; } Curve c2 = curves[q]; Vector3d v2 = Point3d.Subtract(c2.PointAtEnd, c2.PointAtStart); if (Rhino.Geometry.Intersect.Intersection.CurveCurve(c1, c2, 0, 0).Count == 1 && zhefan(c1, c2))///有一个交点 { double ag = Vector3d.VectorAngle(v1, v2); if (ag > Math.PI * 0.5) { ag = Math.PI - ag; } if (ag <= angle)////角度满足要求 { index.Add(q); collect.Add(curves[q]); c1 = collect[collect.Count - 1]; curves[q] = null; flag1 = true; break; } } } if (flag1)////如果有满足情况的曲线,则继续执行上一步操作 { flag3 = false; i--; continue; } //////////////////////////////////////////////////////////////////先判断第一个方向所有满足条件的线 ////////////////////////////////////////////////////////////////// if (!flag2) { flag1 = false; flag2 = true; i--; flag3 = false; index.Reverse(); collect.Reverse(); continue; } last.AddRange(collect, new GH_Path(0, branch, mem)); indexes.AddRange(index, new GH_Path(0, branch, mem)); mem++; curves[i] = null; collect.Clear(); index.Clear(); flag3 = true; flag2 = false; flag1 = false; } DA.SetDataTree(0, last); DA.SetDataTree(1, indexes); }
public Circle LongitudeDegrees(double degrees) { return(LongitudeRadians(RhinoMath.ToRadians(degrees))); }
protected override void SolveInstance(IGH_DataAccess access) { Curve curve = null; List <string> edges = new List <string>(); List <string> fills = new List <string>(); bool order = true; if (!access.GetData(0, ref curve)) { return; } if (!access.GetData(3, ref order)) { return; } access.GetDataList(1, edges); access.GetDataList(2, fills); for (int i = edges.Count - 1; i >= 0; i--) { if (string.IsNullOrWhiteSpace(edges[i])) { edges.RemoveAt(i); } } for (int i = fills.Count - 1; i >= 0; i--) { if (string.IsNullOrWhiteSpace(fills[i])) { fills.RemoveAt(i); } } if (edges.Count == 0 && fills.Count == 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "At least a single edge or fill is required."); return; } Polyline polyline; if (!curve.TryGetPolyline(out polyline)) { curve = curve.ToPolyline(0.1, RhinoMath.ToRadians(0.2), 0.01, 100); curve.TryGetPolyline(out polyline); } if (polyline == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Curve could not be converted to polyline."); return; } GdiShapeGoo goo = new GdiShapeGoo(polyline, edges, fills) { DrawFillsBeforeEdges = order }; access.SetData(0, goo); }
public DisplayBitmapDrawList() { MaximumCachedSortLists = 10; SortAngleTolerance = RhinoMath.ToRadians(5); }
public void ConstructJointsEdgeJoints(int sideDivisions = 2, double dovetailAngleDegrees = 5) { sidePlanesR90SideJoints = new Plane[n][]; if (sideDivisions % 2 == 1) { sideDivisions -= 1; } //sideDivisions = Math.Max(sideDivisions, 0); //1 addPlanes at each corner for (int i = 0; i < n; i++) { //if (sidePlanesBiFlags[i]) { //Check if not bisector int next = NGonsCore.MathUtil.Wrap(i + 1, n); int prev = NGonsCore.MathUtil.Wrap(i - 1, n); sidePlanesR90SideJoints[i] = new Plane[sideDivisions]; //i - side polyline 1 - two polylines //2---1 //3---0 //Interpolate polyline Point3d[] interpolatedPts = NGonsCore.PointUtil.InterpolatePoints( (sideOutlines0[i][0][2] + sideOutlines1[i][1][2]) * 0.5, (sideOutlines0[i][0][3] + sideOutlines1[i][1][3]) * 0.5, sideDivisions, false); for (int j = 0; j < sideDivisions; j++) { int shift = (j % 2 == 0) ? 1 : -1; sidePlanesR90SideJoints[i][j] = new Plane(sidePlanesR90[i]); sidePlanesR90SideJoints[i][j].Rotate(angle90, sidePlanesR90SideJoints[i][j].XAxis); sidePlanesR90SideJoints[i][j].Rotate(shift * RhinoMath.ToRadians(dovetailAngleDegrees), sidePlanesR90SideJoints[i][j].YAxis); sidePlanesR90SideJoints[i][j].Origin = interpolatedPts[j]; //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(new Rectangle3d(sidePlanesR90SideJoints[i][j], new Interval(-0.05, 0.05), new Interval(-0.05, 0.05))); } //} else sidePlanesR90SideJoints[i] = null; } //2 Create zigzag Polylines for (int i = 0; i < n; i++) { Polyline zigzag0; Polyline zigzag1; if (i != 0) { zigzag0 = new Polyline() { sideOutlines0[i][0][2] }; zigzag1 = new Polyline() { sideOutlines0[i][1][2] }; } else { zigzag0 = new Polyline() { sideOutlines1[i][0][2] }; zigzag1 = new Polyline() { sideOutlines1[i][1][2] }; } int next = NGonsCore.MathUtil.Wrap(i + 1, n); int prev = NGonsCore.MathUtil.Wrap(i - 1, n); //Rhino.RhinoApp.WriteLine(sidePlanesBiFlags[i].ToString() + " " + i.ToString()); if (sidePlanesBiFlags[prev] && i != 0) { for (int j = 0; j < sideDivisions; j++) { zigzag0.AddRange(IntersectTwoLinesWithOnePlane(sideOutlines0[i][0].SegmentAt(2), sideOutlines1[i][0].SegmentAt(2), sidePlanesR90SideJoints[i][j], j)); zigzag1.AddRange(IntersectTwoLinesWithOnePlane(sideOutlines0[i][1].SegmentAt(2), sideOutlines1[i][1].SegmentAt(2), sidePlanesR90SideJoints[i][j], j)); } } if (i != 0) { zigzag0.Add(sideOutlines0[i][0][3]); zigzag1.Add(sideOutlines0[i][1][3]); } else { zigzag0.Add(sideOutlines1[i][0][3]); zigzag1.Add(sideOutlines1[i][1][3]); } if (i != n - 1) { zigzag0.Add(sideOutlines0[i][0][0]); zigzag1.Add(sideOutlines0[i][1][0]); } else { zigzag0.Add(sideOutlines1[i][0][0]); zigzag1.Add(sideOutlines1[i][1][0]); } if (sidePlanesBiFlags[i] && i != n - 1) { for (int j = sideDivisions - 1; j >= 0; j--) { zigzag0.AddRange(IntersectTwoLinesWithOnePlane(sideOutlines0[i][0].SegmentAt(0), sideOutlines1[i][0].SegmentAt(0), sidePlanesR90SideJoints[next][j], j, 1)); zigzag1.AddRange(IntersectTwoLinesWithOnePlane(sideOutlines0[i][1].SegmentAt(0), sideOutlines1[i][1].SegmentAt(0), sidePlanesR90SideJoints[next][j], j, 1)); } } if (i != n - 1) { zigzag0.Add(sideOutlines0[i][0][1]); zigzag1.Add(sideOutlines0[i][1][1]); } else { zigzag0.Add(sideOutlines1[i][0][1]); zigzag1.Add(sideOutlines1[i][1][1]); } zigzag0.Close(); zigzag1.Close(); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(zigzag0); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(zigzag1); sideOutlines0[i][0] = zigzag0; sideOutlines0[i][1] = zigzag1; //RhinoDoc.ActiveDoc.Objects.AddPolyline(zigzag0); } }