/// <summary> ///For center axis I need three planes: ///A - Edge plane ///B - Bottom Plane ///C - Section Plane ///Also two points ///And radius /// </summary> /// <param name="p"></param> /// <returns></returns> public DataTree <Polyline> RoundBeams(NGonsCore.MeshProps p, double radius = 0.075) { var dt = new DataTree <Polyline>(); for (int i = 0; i < p.M._countF(); i++) { int[] fe = p.M._fe(i); for (int j = 0; j < p.M._countE(i); j++) { if (this[i, j].isNexor != 0) { Plane edgePlane = this[i, j].ePl; Plane sectionPlane = new Plane(this[i, j].ePl.Origin, this[i, j].ePl.YAxis, this[i, j].ePl.ZAxis); Plane bottomPlane = this[i, j].ePl90Offset; //for getting the points Point3d p1 = PlaneUtil.PlanePlanePlane(this[i, j].foPl[0], this[i, j].foPl[1].MovePlanebyAxis(this.plateThickness), sectionPlane); Point3d p0 = PlaneUtil.PlanePlanePlane(this[i, j].fcPl[2], this[i, j].fcPl[1].MovePlanebyAxis(this.plateThickness), sectionPlane); Point3d pc = PlaneUtil.PlanePlanePlane(this[i, j].fcPl[0], this[i, j].fcPl_foPl, sectionPlane); Point3d po = PlaneUtil.PlanePlanePlane(this[i, j].foPl[2], this[i, j].fcPl_foPl, sectionPlane); //pc.Bake(); //po.Bake(); //if (i == 20) { Line line = this[i, j].line; Circle circle = CircleUtil.GetCircleCenter(edgePlane, bottomPlane, sectionPlane, new List <Point3d> { p0, p1 }, radius); Vector3d v = circle.Center - line.From; line.Transform(Transform.Translation(v)); //Rhino.RhinoDoc.ActiveDoc.Objects.AddCircle(circle); //Rhino.RhinoApp.WriteLine(p.M.IsNaked(p.M._meshE(i, j)).ToString()); int[] on = (p.M.IsNaked(fe[j])) ? new int[] { i, (j + 1).Wrap(fe.Length) } : p.M._OppositeFE(i, j, 1); int[] op = (p.M.IsNaked(fe[j])) ? new int[] { i, (j - 1).Wrap(fe.Length) } : p.M._OppositeFE(i, j, -1); bool onFlag = this[on[0], on[1]].isNexor == 0; bool opFlag = this[op[0], op[1]].isNexor == 0; if (this[on[0], on[1]].isNexor == 0) { on = p.M._OppositeFE(on[0], on[1]); } if (this[op[0], op[1]].isNexor == 0) { op = p.M._OppositeFE(op[0], op[1]); } Plane pl0 = onFlag ? this[on[0], on[1]].foPl[0] : this[on[0], on[1]].fcPl[2]; Plane pl1 = opFlag ? this[op[0], op[1]].foPl[0] : this[op[0], op[1]].fcPl[2]; pl0 = this[i, j].endPl0; pl1 = this[i, j].endPl1; if (this[on[0], on[1]].isNexor != 0 && this[op[0], op[1]].isNexor != 0) { line = new Line(PlaneUtil.LinePlane(line, this[i, j].endPl0), PlaneUtil.LinePlane(line, this[i, j].endPl1)); line.Extend(0.1, 0.1); //line.Transform(Transform.Scale(line.Center(), 2)); this[i, j].pipe = NGonsCore.PipeUtil.CreatePipe( line, this[i, j].id, sectionPlane, radius, pl0.MovePlanebyAxis(0.01, this[i, j].line.Center(), 2, false), pl1.MovePlanebyAxis(0.01, this[i, j].line.Center(), 2, false), 10, -1, true); // Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(pipe.meshloft); //Rhino.RhinoDoc.ActiveDoc.Objects.AddBrep(this[i, j].pipe.breploft); } //} } } } return(dt); }
//Main Methods public DataTree <Polyline> Beams2(NGonsCore.MeshProps p) { DataTree <Polyline> dt = new DataTree <Polyline>(); try { //Edge and End Planes Dictionary <int, int> E = p.M._EAll();//mesh edge - ngon edge for (int i = 0; i < p.M._countF(); i++) { int[] fe = p.M._fe(i); for (int j = 0; j < p.M._countE(i); j++) { if (this[i, j].isNexor != 0) { int e = E[fe[j]];//get ngon Edge by local meshedge this[i, j].ePl90 = p.ePl90[e].ChangeOrigin(this[i, j].line.Center()); this[i, j].ePl = p.ePl[e].ChangeOrigin(this[i, j].line.Center()); this[i, j].ePl90Offset = this[i, j].ePl90.MovePlanebyAxis(depth); int[] o = p.M._OppositeFE(i, j); int i_ = (o[0] != -1) ? o[0] : i; int j_ = (o[1] != -1) ? o[1] : j; int naked = (o[0] != -1) ? 1 : -1; Plane ePl0 = this[i, j].ePl; Plane ePl1 = new Plane(this[i, j].ePl.Origin, this[i, j].ePl.YAxis, this[i, j].ePl.ZAxis); Plane cPl = p.fPl[i]; Plane oPl = p.fPl[i_]; Point3d originC = PlaneUtil.PlanePlanePlane(ePl0, ePl1, cPl); Point3d originO = PlaneUtil.PlanePlanePlane(ePl0, ePl1, oPl); //Plane correspoding to current face plane Plane fcPl = p.fePl[i][j].ChangeOrigin(originC); Plane fcPl90 = p.fePl90[i][j].ChangeOrigin(originC); Vector3d v0 = -fcPl.ZAxis * offset0 * scale; Vector3d v1 = -fcPl.YAxis * plateThickness; Plane fcPl0 = fcPl90; //this[i, j].fcPl.Add(fcPl90); this[i, j].fcPl.Add(fcPl.Translation(v0 * extend)); this[i, j].fcPl.Add(fcPl90.Translation(v0 + v1)); this[i, j].fcPl.Add(this[i, j].ePl.Translation(v0 * 2)); if (i == 10) { //Line line = new Line(originO.zy); //this[i, j].fcPl.Bake(); } //Plane corresponding to opposite plane Plane foPl = p.fePl[i_][j_].ChangeOrigin(originO); Plane foPl90 = p.fePl90[i_][j_].ChangeOrigin(originO); v0 = -foPl.ZAxis * offset0 * scale * naked;//for naked opposite - do i need to flip? v1 = -foPl.YAxis * plateThickness; this[i, j].foPl.Add(this[i, j].ePl.Translation(v0 * 2)); this[i, j].foPl.Add(foPl90.Translation(v0 + v1)); this[i, j].foPl.Add(foPl.Translation(v0 * extend)); //this[i, j].foPl.Add(foPl90); Plane foPl3 = foPl90; //Average plane for chamfer middle part of the beam Line l1 = PlaneUtil.PlanePlane(fcPl90, this[i, j].fcPl[0]); Line l0 = PlaneUtil.PlanePlane(this[i, j].foPl[2], foPl90); this[i, j].fcPl_foPl = new Plane((l0.Center() + l1.Center()) * 0.5, l0.Direction, l0.Center() - l1.Center()); //End Planes - next edge opposite int ne = E[fe.Next(j)]; //get next ngon edge int[] no = p.M._OppositeFE(i, (j + 1).Wrap(p.M._countE(i))); //get next opposite edge this[i, j].endPl0 = (no[0] != -1) ? this[i, j].endPl0 = p.ePl[ne].ChangeOrigin(this[no[0], no[1]].line.Center()) : this[i, j].endPl0 = p.ePl[ne].ChangeOrigin(this[i, j].line.To); //change origin because planes are located at mesh edge this[i, j].endPl0 = this[i, j].endPl0.MovePlanebyAxis(offset0 * 2, this[i, j].line.Center()); //move towards the center //End Planes - prev edge opposite int pe = E[fe.Prev(j)]; //get previous ngon edge int[] po = p.M._OppositeFE(i, (j - 1).Wrap(p.M._countE(i))); ////get prev opposite edge this[i, j].endPl1 = (po[0] != -1) ? p.ePl[pe].ChangeOrigin(this[po[0], po[1]].line.Center()) : p.ePl[pe].ChangeOrigin(this[i, j].line.From); //change origin because planes are located at mesh edge this[i, j].endPl1 = this[i, j].endPl1.MovePlanebyAxis(offset0 * 2, this[i, j].line.Center()); //move towards the center }//is nexor }//for j }//for i //Nodes profiles for (int i = 0; i < p.M._countF(); i++) { int[] fe = p.M._fe(i); for (int j = 0; j < p.M._countE(i); j++) { if (this[i, j].isNexor != 0) { List <Polyline> cutters0 = new List <Polyline>(); List <Plane> sidePlanes = new List <Plane>(); sidePlanes.AddRange(this[i, j].fcPl); sidePlanes.Add(this[i, j].ePl90Offset); sidePlanes.AddRange(this[i, j].foPl); sidePlanes.Add(this[i, j].fcPl_foPl); if ((!p.M.IsNaked(fe[j])))// { //End Planes - next edge opposite int[] op = p.M._OppositeFE(i, j, -1); int[] on = p.M._OppositeFE(i, j, 1); int[] no = p.M._OppositeFE(i, (j + 1).Wrap(fe.Length)); //for end parts int[] po = p.M._OppositeFE(i, (j - 1).Wrap(fe.Length)); //for end parts //First profile Polyline p0 = PolylineUtil.PolylineFromPlanes(this[i, j].endPl0, sidePlanes); //Plane sectionPlaneP0 = p.M.IsNaked(fe.Next(j)) ? this[i, (j + 1).Wrap(fe.Length)].ePl : this[op[0], op[1]].fcPl[0]; if (op[0] != -1) { p0 = PolylineUtil.PolylineFromPlanes(this[op[0], op[1]].fcPl[0], sidePlanes); } List <Plane> sidePlanes1A = new List <Plane>(); sidePlanes1A.AddRange(this[i, j].fcPl); sidePlanes1A.Add(this[i, j].ePl90Offset); sidePlanes1A.Add(this[i, j].foPl[0]); sidePlanes1A.Add(this[i, j].foPl[1].MovePlanebyAxis(plateThickness)); sidePlanes1A.Add(this[i, j].fcPl_foPl); Plane sectionPlaneP3A_ = p.M.IsNaked(fe.Next(j)) ? this[i, (j + 1).Wrap(fe.Length)].foPl[0] : this[op[0], op[1]].foPl[0]; Plane sectionPlaneP3A = p.M.IsNaked(fe.Next(j)) ? this[i, (j + 1).Wrap(fe.Length)].fcPl[2] : this[op[0], op[1]].foPl[0]; if (p.M.IsNaked(fe.Next(j)) && (p.M.TopologyEdges.EdgeLine(fe.Next(j)).To.Z < z || p.M.TopologyEdges.EdgeLine(fe.Next(j)).From.Z < z)) { sectionPlaneP3A_ = ground; this[i, j].endPl0 = ground; } List <Plane> sidePlanes1BExtended = new List <Plane>(); sidePlanes1BExtended.Add(this[i, j].fcPl[0]); sidePlanes1BExtended.Add(this[i, j].ePl90Offset.MovePlanebyAxis(this.depth * 2, this[i, j].line.Center(), 2, true)); sidePlanes1BExtended.Add(this[i, j].foPl[0]); sidePlanes1BExtended.Add(this[i, j].foPl[1].MovePlanebyAxis(plateThickness)); sidePlanes1BExtended.Add(this[i, j].fcPl_foPl); Polyline p2A = PolylineUtil.PolylineFromPlanes(this[op[0], op[1]].fcPl[0], sidePlanes1A); Polyline p3A = PolylineUtil.PolylineFromPlanes(sectionPlaneP3A, sidePlanes1A);//Top Removal - Inner Polyline p3A_ = PolylineUtil.PolylineFromPlanes(sectionPlaneP3A_, sidePlanes1A); Polyline p3A_Extended = PolylineUtil.PolylineFromPlanes(sectionPlaneP3A, sidePlanes1BExtended); //1 cutters0.Add(p3A_Extended); this[i, j].profiles.Add(p2A); this[i, j].profiles.Add(p3A_); if (p.M.IsNaked(fe.Next(j))) { this[i, j].endPl0 = sectionPlaneP3A_; } if (no[0] != -1)//i == 20 && j == 1 && { List <Plane> sidePlanes2 = new List <Plane>(); sidePlanes2.AddRange(this[i, j].fcPl); sidePlanes2.Add(this[i, j].ePl90Offset); sidePlanes2.Add(this[i, j].foPl[0]); sidePlanes2.Add(this[no[0], no[1]].foPl[1].MovePlanebyAxis(plateThickness)); sidePlanes2.Add(this[i, j].fcPl_foPl); List <Plane> sidePlanes2Extended = new List <Plane>(); sidePlanes2Extended.Add(this[i, j].fcPl[0].MovePlanebyAxis(this.plateThickness, this[i, j].line.Center(), 2, false)); sidePlanes2Extended.Add(this[i, j].ePl90Offset.MovePlanebyAxis(this.depth * 2, this[i, j].line.Center(), 2, true)); sidePlanes2Extended.Add(this[i, j].foPl[0].MovePlanebyAxis(this.plateThickness, this[i, j].line.Center(), 2, false)); sidePlanes2Extended.Add(this[no[0], no[1]].foPl[1].MovePlanebyAxis(plateThickness)); sidePlanes2Extended.Add(this[i, j].fcPl_foPl); Polyline p4A = PolylineUtil.PolylineFromPlanes(this[i, j].endPl0, sidePlanes2); //Top Removal - End Polyline p4A_Extended = PolylineUtil.PolylineFromPlanes(this[i, j].endPl0.MovePlanebyAxis(0.00, this[i, j].line.Center(), 2, false), sidePlanes2Extended); //Top Removal - End - 0 cutters0.Insert(0, p4A_Extended); this[i, j].profiles.Add(p3A); this[i, j].profiles.Add(p4A); } //Second profile Polyline p1 = PolylineUtil.PolylineFromPlanes(this[i, j].endPl1, sidePlanes); //Plane sectionPlaneP1 = p.M.IsNaked(fe.Prev(j)) ? this[i, (j - 1).Wrap(fe.Length)].ePl : this[on[0], on[1]].fcPl[0]; if (on[0] != -1) { p1 = PolylineUtil.PolylineFromPlanes(this[on[0], on[1]].fcPl[0], sidePlanes); } List <Plane> sidePlanes1B = new List <Plane>(); sidePlanes1B.AddRange(this[i, j].fcPl); sidePlanes1B.Add(this[i, j].ePl90Offset); sidePlanes1B.Add(this[i, j].foPl[0]); sidePlanes1B.Add(this[i, j].foPl[1].MovePlanebyAxis(plateThickness)); sidePlanes1B.Add(this[i, j].fcPl_foPl); Plane sectionPlaneP3B_ = p.M.IsNaked(fe.Prev(j)) ? this[i, (j - 1).Wrap(fe.Length)].foPl[0] : this[on[0], on[1]].foPl[0]; Plane sectionPlaneP3B = p.M.IsNaked(fe.Prev(j)) ? this[i, (j - 1).Wrap(fe.Length)].fcPl[2] : this[on[0], on[1]].foPl[0]; if (p.M.IsNaked(fe.Prev(j)) && (p.M.TopologyEdges.EdgeLine(fe.Prev(j)).To.Z < z || p.M.TopologyEdges.EdgeLine(fe.Prev(j)).From.Z < z)) { sectionPlaneP3B_ = ground; this[i, j].endPl1 = ground; //p.M.TopologyEdges.EdgeLine(fe[j]).Center().Bake(); } Polyline p2B = PolylineUtil.PolylineFromPlanes(this[on[0], on[1]].fcPl[0], sidePlanes1B); Polyline p3B = PolylineUtil.PolylineFromPlanes(sectionPlaneP3B, sidePlanes1B);//Top Removal - Inner Polyline p3B_ = PolylineUtil.PolylineFromPlanes(sectionPlaneP3B_, sidePlanes1B); Polyline p3B_Extended = PolylineUtil.PolylineFromPlanes(sectionPlaneP3B, sidePlanes1BExtended);//Top Removal - Inner2 cutters0.Add(p3B_Extended); this[i, j].profiles.Add(p2B); this[i, j].profiles.Add(p3B_); if (p.M.IsNaked(fe.Prev(j))) { this[i, j].endPl1 = sectionPlaneP3B_; } if (po[0] != -1)//i == 20 && j == 1 && { List <Plane> sidePlanes2 = new List <Plane>(); sidePlanes2.AddRange(this[i, j].fcPl); sidePlanes2.Add(this[i, j].ePl90Offset); sidePlanes2.Add(this[i, j].foPl[0]); sidePlanes2.Add(this[po[0], po[1]].foPl[1].MovePlanebyAxis(plateThickness)); sidePlanes2.Add(this[i, j].fcPl_foPl); List <Plane> sidePlanes2Extended = new List <Plane>(); sidePlanes2Extended.Add(this[i, j].fcPl[0].MovePlanebyAxis(this.plateThickness, this[i, j].line.Center(), 2, false)); sidePlanes2Extended.Add(this[i, j].ePl90Offset.MovePlanebyAxis(this.depth * 2, this[i, j].line.Center(), 2, true)); sidePlanes2Extended.Add(this[i, j].foPl[0].MovePlanebyAxis(this.plateThickness, this[i, j].line.Center(), 2, false)); sidePlanes2Extended.Add(this[po[0], po[1]].foPl[1].MovePlanebyAxis(plateThickness)); sidePlanes2Extended.Add(this[i, j].fcPl_foPl); Polyline p4B = PolylineUtil.PolylineFromPlanes(this[i, j].endPl1, sidePlanes2); //Top Removal - End Polyline p4B_Extended = PolylineUtil.PolylineFromPlanes(this[i, j].endPl1.MovePlanebyAxis(0.00, this[i, j].line.Center(), 2, false), sidePlanes2Extended); //Top Removal - End //3 cutters0.Add(p4B_Extended); //p4B_Extended.Bake(); //p2.Bake(); //p3.Bake(); //p4.Bake(); this[i, j].profiles.Add(p4B); this[i, j].profiles.Add(p3B); } this[i, j].profiles.Add(p0); this[i, j].profiles.Add(p1); //End profile } else if (this[i, j].isNexor == 1) { List <Plane> sidePlanesNaked = new List <Plane>(); sidePlanesNaked.AddRange(this[i, j].fcPl); sidePlanesNaked.Add(this[i, j].ePl90Offset); sidePlanesNaked.Add(this[i, j].foPl[0]); sidePlanesNaked.Add(this[i, j].fcPl_foPl); Plane planeA = (this[i, j].endPl0.Origin.Z < z) ? ground : this[i, j].endPl0; Plane planeB = (this[i, j].endPl1.Origin.Z < z) ? ground : this[i, j].endPl1; if (this[i, j].endPl0.Origin.Z < z) { this[i, j].endPl0 = ground; } if (this[i, j].endPl1.Origin.Z < z) { this[i, j].endPl1 = ground; } Polyline p0 = PolylineUtil.PolylineFromPlanes(planeA, sidePlanesNaked); Polyline p1 = PolylineUtil.PolylineFromPlanes(planeB, sidePlanesNaked); this[i, j].profiles.Add(p0); this[i, j].profiles.Add(p1); } else if (this[i, j].isNexor == -1) { List <Plane> sidePlanesNaked = new List <Plane>(); sidePlanesNaked.Add(this[i, j].ePl90Offset); sidePlanesNaked.Add(this[i, (j + 1).Wrap(fe.Length)].fcPl[2]); sidePlanesNaked.Add(this[i, (j + 1).Wrap(fe.Length)].fcPl[1]); sidePlanesNaked.Add(this[i, (j + 1).Wrap(fe.Length)].fcPl[0]); sidePlanesNaked.Add(this[i, j].fcPl_foPl); sidePlanesNaked.AddRange(this[i, (j - 1).Wrap(fe.Length)].fcPl); this[i, j].endPl0 = this[i, (j + 1).Wrap(fe.Length)].fcPl[0]; this[i, j].endPl1 = this[i, (j - 1).Wrap(fe.Length)].fcPl[0]; Polyline p0 = PolylineUtil.PolylineFromPlanes(this[i, j].fcPl[0], sidePlanesNaked); Polyline p1 = PolylineUtil.PolylineFromPlanes(this[i, j].foPl[0], sidePlanesNaked); //p0.Bake(); //p1.Bake(); this[i, j].profiles.Add(p0); this[i, j].profiles.Add(p1); //p0.Bake(); //p1.Bake(); } this[i, j].CNC_Cuts.AddRange(cutters0, new Grasshopper.Kernel.Data.GH_Path(i, j)); } } } foreach (var n in this._nexors) { if (n.isNexor != 0) { var path = new Grasshopper.Kernel.Data.GH_Path(n.idNested[0], n.idNested[1]); if (n.profiles.Count > 0) { dt.AddRange(n.profiles, path); } } } } catch (Exception e) { Rhino.RhinoApp.WriteLine(e.ToString()); } return(dt); }
public DataTree <Polyline> Panels(NGonsCore.MeshProps p) { //Draw panels DataTree <Polyline> dtPlates = new DataTree <Polyline>(); for (int i = 0; i < p.M._countF(); i++) { Plane panel0 = p.fPl[i]; Plane panel1 = p.fPl[i].MovePlanebyAxis(-plateThickness); Plane panel2 = panel1.MovePlanebyAxis(plateThickness * 10); List <Plane> sidePlanes = new List <Plane>(); for (int j = 0; j < p.M._countE(i); j++) { if (this[i, j].isNexor != 0) { sidePlanes.Add(this[i, j].fcPl[0]); } else { int[] oppo = p.M._OppositeFE(i, j); Plane sidePlane = Plane.Unset; if (oppo[0] != -1) { Plane oppoPlane = this[oppo[0], oppo[1]].ePl; Plane ePl0 = oppoPlane; Plane ePl1 = new Plane(oppoPlane.Origin, oppoPlane.YAxis, oppoPlane.ZAxis); Plane left = p.fPl[i]; Plane right = p.fPl[oppo[0]]; Point3d originRight = PlaneUtil.PlanePlanePlane(ePl0, ePl1, left); Point3d originLeft = PlaneUtil.PlanePlanePlane(ePl0, ePl1, right); sidePlane = p.fePl[i][j].ChangeOrigin(originRight); } else { sidePlane = p.fePl[i][j]; } sidePlane = sidePlane.MovePlanebyAxis(offset0 * scale * extend, panel0.Origin); sidePlanes.Add(sidePlane); } } Polyline panelOutline0 = PolylineUtil.PolylineFromPlanes(panel0, sidePlanes); Polyline panelOutline1 = PolylineUtil.PolylineFromPlanes(panel1, sidePlanes); Polyline panelOutline2 = PolylineUtil.PolylineFromPlanes(panel2, sidePlanes); dtPlates.Add(panelOutline0, new Grasshopper.Kernel.Data.GH_Path(i)); dtPlates.Add(panelOutline1, new Grasshopper.Kernel.Data.GH_Path(i)); for (int j = 0; j < p.M._countE(i); j++) { int[] op = p.M._OppositeFE(i, j); if (this[i, j].isNexor != 0) { this[i, j].CNCtopProfileCuts.Add(panelOutline1); this[i, j].CNCtopProfileCuts.Add(panelOutline2); } if (op[0] != -1) { this[op[0], op[1]].CNCtopProfileCuts.Add(panelOutline1); this[op[0], op[1]].CNCtopProfileCuts.Add(panelOutline2); } } } return(dtPlates); List <Line> pipes = new List <Line>(); for (int i = 0; i < p.M._countF(); i++) { int[] fe = p.M._fe(i); for (int j = 0; j < p.M._countE(i); j++) { if (this[i, j].isNexor != 0 && !p.M.IsNaked(fe[j])) { Line line = this[i, j].line; line.Transform(Transform.Translation(this[i, j].ePl.YAxis * -movePipeAxis)); line = new Line(PlaneUtil.LinePlane(line, this[i, j].endPl0), PlaneUtil.LinePlane(line, this[i, j].endPl1)); line.Extend(0.2, 0.2); pipes.Add(line); } } } }