private static List <Polyline> DrawCorridor(List <Point3d> anchors, List <Line> mainAxis) { List <Polyline> corridor = new List <Polyline>(); if (anchors.Count < 2) { return(null); } List <Rectangle3d> rectList = new List <Rectangle3d>(); for (int i = 0; i < anchors.Count - 1; i++) { Rectangle3d tempRect = RectangleTools.DrawP2PRect(anchors[i], anchors[i + 1], CorridorDimension.OneWayWidth); rectList.Add(tempRect); } if (rectList.Count > 1) { Curve intersected = rectList[0].ToNurbsCurve(); for (int i = 0; i < rectList.Count - 1; i++) { List <Curve> unionCurves = new List <Curve>(); unionCurves.Add(intersected); unionCurves.Add(rectList[i + 1].ToNurbsCurve()); intersected = Curve.CreateBooleanUnion(unionCurves)[0]; } corridor.Add(CurveTools.ToPolyline(intersected)); } return(corridor); }
private static List <Polyline> RemoveOverlapSeg(Polyline trimmee, Polyline trimmer) { List <Polyline> trimmed = new List <Polyline>(); List <Curve> memberToJoin = new List <Curve>(); Curve trimmerCrv = trimmer.ToNurbsCurve(); List <Curve> trimmeeSeg = trimmee.ToNurbsCurve().DuplicateSegments().ToList(); foreach (Curve i in trimmeeSeg) { if (!CurveTools.IsOverlap(i, trimmerCrv, 0.005)) { memberToJoin.Add(i); } } List <Curve> joinedCrvs = Curve.JoinCurves(memberToJoin, 0.5, true).ToList(); foreach (Curve i in joinedCrvs) { trimmed.Add(CurveTools.ToPolyline(i)); } if (trimmed.Count == 0) { return(new List <Polyline>()); } return(trimmed); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { RhinoApp.WriteLine("안녕하세요 방만드는기계 입니다."); // Polyline outline = new Polyline(); Polyline coreLine = new Polyline(); Polyline landing = new Polyline(); GetObject getPolyline = new GetObject(); getPolyline.SetCommandPrompt("외곽선,코어,랜딩 입력해주세요"); getPolyline.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; getPolyline.GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve; getPolyline.SubObjectSelect = false; getPolyline.GetMultiple(3, 0); if (getPolyline.CommandResult() != Result.Success) { RhinoApp.WriteLine("달라고!"); return(getPolyline.CommandResult()); } else { RhinoApp.WriteLine("입력받았습니다."); } if (null == getPolyline.Object(0).Curve()) { RhinoApp.WriteLine("없잖아!"); return(getPolyline.CommandResult()); } List <Polyline> testPoly = new List <Polyline>(); foreach (var i in getPolyline.Objects()) { testPoly.Add(CurveTools.ToPolyline(i.Curve())); } outline = testPoly[0]; coreLine = testPoly[1]; landing = testPoly[2]; List <Polyline> rooms = Debugger.DebugRoom(outline, coreLine, landing); foreach (Polyline i in rooms) { doc.Objects.AddCurve(i.ToNurbsCurve()); } doc.Views.Redraw(); RhinoApp.WriteLine("최선을 다했습니다만..."); return(Result.Success); }
private static List <Polyline> GetBooleanDifference(Polyline outline, Polyline coreUnion) { List <Polyline> trimmedOutline = new List <Polyline>(); List <Curve> trimmed = Curve.CreateBooleanDifference(outline.ToNurbsCurve(), coreUnion.ToNurbsCurve()).ToList(); foreach (Curve i in trimmed) { trimmedOutline.Add(CurveTools.ToPolyline(i)); } return(trimmedOutline); }
private static List <Polyline> DrawCorridor(List <Point3d> anchors, List <Line> baseAxis, double subLength) { List <Polyline> corridor = new List <Polyline>(); Rectangle3d subCorridor = RectangleTools.DrawP2PRect(anchors[0], anchors[1], subLength, CorridorDimension.TwoWayWidth); Rectangle3d mainCorridor = RectangleTools.DrawP2PRect(anchors[1], anchors[2], CorridorDimension.TwoWayWidth, subLength); List <Curve> forUnion = new List <Curve>(); forUnion.Add(subCorridor.ToNurbsCurve()); forUnion.Add(mainCorridor.ToNurbsCurve()); corridor.Add(CurveTools.ToPolyline(Curve.CreateBooleanUnion(forUnion)[0])); return(corridor); }
//process method private List <Room> MakeRooms(List <LabeledOutline> outlinelabels, List <List <Room> > allocatedRoom) { //draw outline. List <Polyline> roomOutlines = new List <Polyline>(); for (int i = 0; i < outlinelabels.Count; i++) { roomOutlines.AddRange( DrawRoomAtEachPart(outlinelabels[i], allocatedRoom[i].Select(n => n.Area).ToList())); } //merge smallRoom. //tolerance 문제 있을듯 if (roomOutlines.Count > 1 && roomOutlines.Last().GetArea() < Dimensions.MinRoomArea) { Curve lastRoom = roomOutlines.Last().ToNurbsCurve(); roomOutlines.RemoveAt(roomOutlines.Count - 1); Curve preLastRoom = roomOutlines.Last().ToNurbsCurve(); roomOutlines.RemoveAt(roomOutlines.Count - 1); Curve[] merged = Curve.CreateBooleanUnion(new List <Curve> { lastRoom, preLastRoom }); merged.OrderByDescending(n => n.GetArea()); roomOutlines.Add(CurveTools.ToPolyline(merged.First())); } //assign to RoomClass List <Room> rooms = new List <Room>(); List <Room> outlineLackedRoom = new List <Room>(); allocatedRoom.ForEach(n => outlineLackedRoom.AddRange(n)); for (int i = 0; i < roomOutlines.Count; i++) { Room currentRoom = outlineLackedRoom[i]; currentRoom.Outline = roomOutlines[i]; currentRoom.Area = roomOutlines[i].GetArea(); rooms.Add(currentRoom); } return(rooms); }
//method private static Polyline GetCoreUnion(Core core, List <Polyline> corridor) { List <Curve> coreAndCorridor = new List <Curve>(); coreAndCorridor.Add(core.Outline.ToNurbsCurve()); foreach (Polyline i in corridor) { coreAndCorridor.Add(i.ToNurbsCurve()); } if (coreAndCorridor.Count == 1) { return(core.Outline); } Curve union = Curve.CreateBooleanUnion(coreAndCorridor)[0]; return(CurveTools.ToPolyline(union)); }
public static List <Brep> DrawHouse(Household hhp) { double height = Consts.FloorHeight; Curve outline = hhp.GetOutline(); Polyline outPoly = CurveTools.ToPolyline(outline); Brep x = Extrusion.Create(outline, height, true).ToBrep(); x.CapPlanarHoles(1); double windowSide = 300; double windowLow = 300; double windowHeight = 2100; double windowDepth = 200; List <Brep> wins = new List <Brep>(); for (int i = 0; i < hhp.LightingEdge.Count; i++) { //Rhino.RhinoDoc.ActiveDoc.Objects.Add(hhp.LightingEdge[i].ToNurbsCurve()); //var c = hhp.LightingEdge[i].ToNurbsCurve().Trim(CurveEnd.Both, 300); //var p1 = c.PointAtStart + Vector3d.ZAxis * 300; //var p2 = c.PointAtStart + Vector3d.ZAxis * 2400; //var p3 = c.PointAtEnd + Vector3d.ZAxis * 2400; //var p4 = c.PointAtEnd + Vector3d.ZAxis * 300; //Brep[] open = Brep.CreatePlanarBreps(new PolylineCurve(new Point3d[] { p1, p2, p3, p4, p1 })); Line tempLine = hhp.LightingEdge[i]; Point3d midPoint = tempLine.PointAt(0.5); Vector3d windowVec = tempLine.UnitTangent; windowVec.Rotate(Math.PI / 2, Vector3d.ZAxis); midPoint.Transform(Transform.Translation(Vector3d.Multiply(windowVec, 10))); if (hhp.GetOutline().Contains(midPoint) == Rhino.Geometry.PointContainment.Inside) { tempLine.Flip(); } tempLine.Extend(-windowSide, -windowSide); Curve tempCurve = tempLine.ToNurbsCurve(); tempCurve.Translate(Vector3d.Multiply(Vector3d.ZAxis, windowLow)); Point3d pt1 = tempCurve.PointAtStart; Point3d pt2 = tempCurve.PointAtEnd; Point3d pt3 = tempCurve.PointAtEnd; pt3.Transform(Transform.Translation(Vector3d.Multiply(Vector3d.ZAxis, windowHeight))); Point3d pt4 = tempCurve.PointAtStart; pt4.Transform(Transform.Translation(Vector3d.Multiply(Vector3d.ZAxis, windowHeight))); Point3d pt5 = tempCurve.PointAtStart; List <Point3d> windowPoints = new List <Point3d>(); windowPoints.Add(pt1); windowPoints.Add(pt2); windowPoints.Add(pt3); windowPoints.Add(pt4); windowPoints.Add(pt5); Polyline windowPolyline = new Polyline(windowPoints); Curve win = windowPolyline.ToNurbsCurve(); Plane windowPlane; win.TryGetPlane(out windowPlane); Vector3d windowNormal = windowPlane.Normal; Curve windowCurve = win.Duplicate() as Curve; windowCurve.Translate(Vector3d.Multiply(windowNormal, windowDepth)); Surface windowSurface = Surface.CreateExtrusion(windowCurve, Vector3d.Multiply(windowNormal, -windowDepth * 2)); Brep windowBrep = windowSurface.ToBrep(); Brep[] withHolesTemp = x.Split(windowBrep, 1); if (withHolesTemp.Length != 0) { x = withHolesTemp[0]; } Curve duplicatedWindowCurve = (win.Duplicate() as Curve); duplicatedWindowCurve.Transform(Transform.Translation(windowNormal * (windowDepth - 100))); Curve windowCurveBottom = duplicatedWindowCurve.DuplicateSegments()[0]; Curve heightCurve = duplicatedWindowCurve.DuplicateSegments()[1]; wins.AddRange(DrawWindowAll(windowCurveBottom, heightCurve.GetLength(), false)); Curve[] tempLoftBase = { win, duplicatedWindowCurve }; Curve pathCurve = new LineCurve(Point3d.Origin, new Point3d(windowNormal * (-windowDepth + 100))); wins.Add(Brep.JoinBreps(Brep.CreateFromLoft(tempLoftBase, Point3d.Unset, Point3d.Unset, LoftType.Normal, false), 0)[0]); } //1. 양쪽에서 300씩 , 위400 아래300 사각형.빵꾸. 안쪽으로 200 //->창틀 //2. 사방 30씩, 안쪽으로 100 //->창문와꾸 //3. 창 안쪽에서 20, 창문와꾸 30, 바깥쪽50 ,길이 1200 * 2 //4. ㅊ //Brep w1 = Brep.create hhp.LightingEdge[0] wins.Add(x); return(wins); }
private static PartitionParam DrawAtMultiFoldOutline(PartitionParam param, double targetArea, List <Point3d> outlineVertex) { Line mainLine = GetMainLine(param, outlineVertex); List <Point3d> canMakePerpVertex = new List <Point3d>(); Vector3d mainAlign = mainLine.UnitTangent; Vector3d mainPerp = VectorTools.RotateVectorXY(mainAlign, Math.PI / 2); Point3d origin = param.OriginPost.Point; bool isMainAlignSameAsPostNormal = mainAlign.IsParallelTo(param.OriginPost.BaseLine.UnitNormal, 0.005) == 1; if (!isMainAlignSameAsPostNormal) { int originIndex = param.OutlineLabel.Core.FindIndex (i => i.PureLine == param.OriginPost.BasePureLine); param.OriginPost = new PartitionOrigin(origin, param.OutlineLabel.Core[originIndex - 1]); mainPerp = VectorTools.RotateVectorXY(mainAlign, -Math.PI / 2); } int lastVertexIndex = outlineVertex.Count - 1; for (int i = 1; i < lastVertexIndex; i++) { Vector3d toPreVector = new Vector3d(outlineVertex[i - 1] - outlineVertex[i]); Vector3d toPostVector = new Vector3d(outlineVertex[i + 1] - outlineVertex[i]); Vector3d toMainVector = -mainPerp; if (IsBetweenVector(toPreVector, toPostVector, toMainVector)) { canMakePerpVertex.Add(outlineVertex[i]); } } //SeivePerpVertex List <Point3d> finalVertex = new List <Point3d>(); foreach (Point3d i in outlineVertex) { Line toBaseLine = PCXTools.PCXByEquationStrict(i, CurveTools.ToPolyline(mainLine.ToNurbsCurve()), -mainPerp); Line toOutline = PCXTools.PCXByEquationStrict(toBaseLine.PointAt(1), param.OutlineLabel.Pure, mainPerp); if (toOutline.PointAt(1).DistanceTo(i) < 0.5) { finalVertex.Add(i); } } //DrawAtEachVertex List <PartitionParam> outputCandidate = new List <PartitionParam>(); foreach (Point3d i in finalVertex) { Line toBaseLine = PCXTools.PCXByEquationStrict(i, CurveTools.ToPolyline(mainLine.ToNurbsCurve()), -mainPerp); Point3d tempAnchor = toBaseLine.PointAt(1); Line toOutline = PCXTools.PCXByEquationStrict(tempAnchor, param.OutlineLabel.Pure, mainPerp); if (toOutline.PointAt(1).DistanceTo(i) > 0.5) { continue; } List <RoomLine> tempPartition = new List <RoomLine>(); tempPartition.Add(new RoomLine(new Line(origin, tempAnchor), LineType.Inner)); tempPartition.Add(new RoomLine(new Line(tempAnchor, i), LineType.Inner)); PartitionParam tempParam = new PartitionParam(param); tempParam.PartitionPost = new Partition(tempPartition, param.OriginPost); outputCandidate.Add(tempParam); } outputCandidate.Add(PartitionMaker.DrawOrtho(param)); //TestCandidate //나중에 수정.. 지금은 면적일치정도로만.. Plane cornerPlane = new Plane(origin, mainAlign, mainPerp); CornerComparer comparer = new CornerComparer(); List <PartitionParam> seived = comparer.Seive(outputCandidate, targetArea, cornerPlane); return(seived[0]); }