public static Curve LineFromString(string data, Curve bounds) { var dims = bounds.GetBoundingBox(Plane.WorldXY); var maxCorner = dims.Max; var minCorner = dims.Min; var range = maxCorner.X - minCorner.X; var rangeInc = range / 6; var mid = (maxCorner + minCorner) / 2; var reflectionPlane = Plane.WorldZX; reflectionPlane.Origin = mid; var xform = Transform.Mirror(reflectionPlane); var coords = data.Split(':')[1].Replace("(", "").Replace(")", "").Split(','); var startPt = new Point3d(Convert.ToDouble(coords[0]) * rangeInc, Convert.ToDouble(coords[1]) * rangeInc, 0); var endPt = new Point3d(Convert.ToDouble(coords[2]) * rangeInc, Convert.ToDouble(coords[3]) * rangeInc, 0); startPt = startPt + minCorner; endPt = endPt + minCorner; var output = new LineCurve(startPt, endPt); output.Transform(xform); return(output); }
private static List <Brep> drawWindow(WindowType windowType, Curve baseCurve, double height) { List <Brep> output = new List <Brep>(); double paneSize = 1200; double frameWidth = 30; //Get Frame Brep windowFrame = drawWindowFrame(baseCurve, height, 30, 100); //Get Pane double paneBaseStart; double paneBaseEnd; baseCurve.LengthParameter(frameWidth, out paneBaseStart); baseCurve.LengthParameter(baseCurve.GetLength() - frameWidth, out paneBaseEnd); Curve paneBase = new LineCurve(baseCurve.PointAt(paneBaseStart), baseCurve.PointAt(paneBaseEnd)); paneBase.Transform(Transform.Translation(Vector3d.ZAxis * frameWidth)); List <Brep> pane = drawPane(windowType, paneBase, height - frameWidth * 2, paneSize, 50, 30, 100); //Make Return output.AddRange(pane); output.Add(windowFrame); return(output); }
public override IGH_GeometricGoo Transform(Transform xform) { if (Value == null) { return(null); } if (Value.Line == null) { return(null); } GsaElement1d elem = Value.Duplicate(); LineCurve xLn = elem.Line; xLn.Transform(xform); elem.Line = xLn; return(new GsaElement1dGoo(elem)); }
public static Elevation drawElevation(Curve baseCurve, List <List <Household> > houseHolds, List <Core> cores) { double storiesHeight = Consts.FloorHeight; double pilotiHeight = Consts.PilotiHeight; double windowSide = 300; double windowLow = 300; double windowHeight = 2100; Curve groundCurve = new LineCurve(new Point3d(0, 0, 0), new Point3d(baseCurve.GetLength(), 0, 0)); List <Curve> outlineCurve = new List <Curve>(); List <Curve> windowDetail = new List <Curve>(); List <Curve> banister = new List <Curve>(); List <Curve> core = new List <Curve>(); List <double> widthList = new List <double>(); foreach (List <Household> i in houseHolds) { foreach (Household j in i) { widthList.Add(j.YLengthA); } } List <double> uniqueWidthList = widthList.Distinct().ToList(); uniqueWidthList.Sort(); List <Brep> tempElevationBase = new List <Brep>(); List <Curve> BalconyBase = new List <Curve>(); List <double> pilotiParameter = new List <double>(); List <Curve> coreBase = new List <Curve>(); for (int h = 0; h < houseHolds.Count(); h++) { for (int i = 0; i < houseHolds[h].Count(); i++) { Point3d start = houseHolds[h][i].Origin + houseHolds[h][i].XDirection * (-houseHolds[h][i].XLengthB); Point3d end = houseHolds[h][i].Origin + houseHolds[h][i].XDirection * (houseHolds[h][i].XLengthA - houseHolds[h][i].XLengthB); double startDomain; double endDomain; baseCurve.ClosestPoint(start, out startDomain); baseCurve.ClosestPoint(end, out endDomain); if (h == 0) { pilotiParameter.Add((endDomain - baseCurve.Domain.T0) * baseCurve.GetLength() + groundCurve.Domain.T0); pilotiParameter.Add((startDomain - baseCurve.Domain.T0) * baseCurve.GetLength() + groundCurve.Domain.T0); } Curve tempHousingBase = new LineCurve(groundCurve.PointAt((startDomain - baseCurve.Domain.T0) * baseCurve.GetLength() + groundCurve.Domain.T0), groundCurve.PointAt((endDomain - baseCurve.Domain.T0) * baseCurve.GetLength() + groundCurve.Domain.T0)); tempHousingBase.Transform(Transform.Translation(new Vector3d(0, start.Z, 0))); Curve tempHousingTop = tempHousingBase.DuplicateCurve(); tempHousingTop.Transform(Transform.Translation(new Vector3d(0, storiesHeight, 0))); Curve[] tempLoftBase = { tempHousingBase, tempHousingTop }; Brep tempHousingBrep = Brep.CreateFromLoft(tempLoftBase, Point3d.Unset, Point3d.Unset, LoftType.Straight, false)[0]; Curve tempBalconyBase = tempHousingBase.DuplicateCurve(); tempBalconyBase.Transform(Transform.Translation(new Vector3d(0, windowLow, 0))); double balconyBaseStart; double balconyBaseEnd; tempBalconyBase.LengthParameter(windowSide, out balconyBaseStart); tempBalconyBase.LengthParameter(tempBalconyBase.GetLength() - windowSide, out balconyBaseEnd); tempBalconyBase = new LineCurve(tempBalconyBase.PointAt(balconyBaseStart), tempBalconyBase.PointAt(balconyBaseEnd)); tempElevationBase.Add(tempHousingBrep); BalconyBase.Add(tempBalconyBase); } } for (int i = 0; i < cores.Count(); i++) { Point3d tempCoreStart = cores[i].Origin; Point3d tempCoreEnd = cores[i].Origin + cores[i].XDirection * cores[i].Width; double startDomain; double endDomain; baseCurve.ClosestPoint(tempCoreStart, out startDomain); baseCurve.ClosestPoint(tempCoreEnd, out endDomain); Curve tempCoreBase = new LineCurve(groundCurve.PointAt((startDomain - baseCurve.Domain.T0) * baseCurve.GetLength() + groundCurve.Domain.T0), groundCurve.PointAt((endDomain - baseCurve.Domain.T0) * baseCurve.GetLength() + groundCurve.Domain.T0)); coreBase.Add(tempCoreBase); } List <List <Brep> > elevationBrepSortedByWidth = new List <List <Brep> >(); for (int i = 0; i < uniqueWidthList.Count(); i++) { elevationBrepSortedByWidth.Add(new List <Brep>()); } for (int i = 0; i < widthList.Count; i++) { int tempWidthIndex = uniqueWidthList.IndexOf(widthList[i]); elevationBrepSortedByWidth[tempWidthIndex].Add(tempElevationBase[i]); } //elevationBrepSortedByWidth[elevationBrepSortedByWidth.Count() - 1].AddRange(DrawPiloti(groundCurve, pilotiParameter.Distinct().ToList(), pilotiHeight)); List <Curve> joinedOutLineCurve = new List <Curve>(); foreach (List <Brep> i in elevationBrepSortedByWidth) { Brep[] joinedBreps = Brep.JoinBreps(i, 2); foreach (Brep j in joinedBreps) { outlineCurve.AddRange(j.DuplicateNakedEdgeCurves(true, true).ToList()); joinedOutLineCurve.AddRange(Curve.JoinCurves(j.DuplicateNakedEdgeCurves(true, true).ToList()).ToList()); } } for (int i = 0; i < coreBase.Count(); i++) { Curve coreBoundary = offsetOneSide(coreBase[i], (cores[i].Stories + 1) * Consts.FloorHeight + Consts.PilotiHeight); core.AddRange(getOuterCurve(coreBoundary, joinedOutLineCurve)); } foreach (Curve h in BalconyBase) { double[] target = { double.MaxValue, 2, 2 }; List <object> typeList = new List <object>(); List <Curve> splittedBaseCurve = divideBaseCurve(h, target, out typeList); for (int i = 0; i < splittedBaseCurve.Count(); i++) { List <string> windowTypeList = Enum.GetValues(typeof(WindowType)).Cast <WindowType>().Select(v => v.ToString()).ToList(); if (windowTypeList.IndexOf(typeList[i].ToString()) != -1) { int index = windowTypeList.IndexOf(typeList[i].ToString()); List <Curve> tempWindow = drawWindow((WindowType)index, splittedBaseCurve[i], windowHeight); windowDetail.AddRange(tempWindow); List <Curve> tempBanister = drawBanister(splittedBaseCurve[i], 25, 900); banister.AddRange(tempBanister); } } } return(new Elevation(outlineCurve, windowDetail, banister, core)); }
public static Section drawSection(List <Curve> baseCurve, List <List <List <Household> > > households, List <List <Core> > cores, Plot plot) { double storyHeight = 2800; double floorLow = 200; double wallThickness = 200; List <int> index = new List <int>(); Curve perpCurve = new LineCurve(Point3d.Origin, Point3d.Origin); List <Curve> Boundary = new List <Curve>(); List <Curve> Room = new List <Curve>(); List <Curve> Core = new List <Curve>(); List <RoomNamecard> roomName = new List <RoomNamecard>(); List <Curve> JoinedBoundaryCrv = new List <Curve>(); List <Curve> CoreBase = new List <Curve>(); List <double> uniqueParameter = getUniqueParameter(baseCurve, plot, out perpCurve, out index); Curve groundCurve = new LineCurve(Point3d.Origin, new Point3d(perpCurve.GetLength(), 0, 0)); for (int i = 0; i < index.Count(); i++) { Core tempCoreProperty = cores[index[i]][0]; Point3d tempCoreStart = tempCoreProperty.Origin; Point3d tempCoreEnd = tempCoreProperty.Origin + tempCoreProperty.YDirection * tempCoreProperty.Depth; double tempStartParam; double tempEndParam; perpCurve.ClosestPoint(tempCoreStart, out tempStartParam); perpCurve.ClosestPoint(tempCoreEnd, out tempEndParam); Curve tempCoreBase = new LineCurve(groundCurve.PointAt(tempStartParam), groundCurve.PointAt(tempEndParam)); CoreBase.Add(offsetOneSide(tempCoreBase, Consts.PilotiHeight + Consts.FloorHeight * (tempCoreProperty.Stories + 1))); } for (int i = 0; i < uniqueParameter.Count(); i++) { List <Brep> boundary = new List <Brep>(); int tempIntersectIndex = 0; for (int j = 0; j < households[i].Count(); j++) { Household tempHousehold = households[i][j][tempIntersectIndex]; double widthAsParameter = tempHousehold.YLengthA * (groundCurve.Domain.T1 - groundCurve.Domain.T0) / groundCurve.GetLength(); Point3d tempStart = groundCurve.PointAt(uniqueParameter[i] - widthAsParameter / 2); Point3d tempEnd = groundCurve.PointAt(uniqueParameter[i] + widthAsParameter / 2); Curve tempBase = new LineCurve(tempStart, tempEnd); tempBase.Transform(Transform.Translation(new Vector3d(0, tempHousehold.Origin.Z, 0))); Curve tempLoftBase = tempBase.DuplicateCurve(); tempLoftBase.Transform(Transform.Translation(new Vector3d(0, storyHeight, 0))); Curve[] tempLoftBaseSet = { tempBase, tempLoftBase }; Brep tempLoftedBrep = Brep.CreateFromLoft(tempLoftBaseSet, Point3d.Unset, Point3d.Unset, LoftType.Straight, false)[0]; boundary.Add(tempLoftedBrep); Curve roomBase = tempBase.DuplicateCurve(); roomBase.Transform(Transform.Translation(new Vector3d(0, floorLow, 0))); double tempRoombaseStart; double tempRoombaseEnd; roomBase.LengthParameter(wallThickness, out tempRoombaseStart); roomBase.LengthParameter(roomBase.GetLength() - wallThickness, out tempRoombaseEnd); roomBase = new LineCurve(roomBase.PointAt(tempRoombaseStart), roomBase.PointAt(tempRoombaseEnd)); Curve room = offsetOneSide(roomBase, storyHeight - floorLow * 2); RoomNamecard tempNamecard = RoomNamecard.CreateRoomNamecard(roomBase.PointAt(roomBase.Domain.Mid) + new Point3d(0, (storyHeight - floorLow * 2) / 2, 0), tempHousehold.GetArea(), storyHeight - floorLow * 2); Room.Add(room); roomName.Add(tempNamecard); } Brep[] joinedBoundary = Brep.JoinBreps(boundary, 0.1); foreach (Brep j in joinedBoundary) { Curve[] tempNakedEdge = j.DuplicateNakedEdgeCurves(true, true); Boundary.AddRange(tempNakedEdge.ToList()); JoinedBoundaryCrv.AddRange(Curve.JoinCurves(tempNakedEdge).ToList()); } } List <Surroundinginfo> surrounding = checkSurrounding(perpCurve, plot, groundCurve); return(new Section(Boundary, Room, Core, surrounding, roomName)); }
/// <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) { int sides = 3; int iter = 3; int length = 5; if (!DA.GetData(0, ref sides)) { return; } if (!DA.GetData(1, ref iter)) { return; } if (!DA.GetData(2, ref length)) { return; } if (sides <= 2) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Number of sides must be greater than 2."); return; } if (iter < 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Number of iterations must be equal to or greater than 0."); return; } if (length <= 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Length of side must be a natural number."); return; } Double l = length; Double s = sides; List <Point3d> VerticesOut = new List <Point3d>(); List <LineCurve> CurvesOut = new List <LineCurve>(); List <Point3d> points = new List <Point3d>(); List <LineCurve> segments = new List <LineCurve>(); // making the initial polygon Point3d p0 = new Point3d(l / (2 * (Math.Cos(Math.PI * (s - 2) / (2 * s)))), 0, 0); points.Add(p0); for (var i = 0; i < s - 1; i++) { Point3d p1 = new Point3d(p0); p1.Transform(Transform.Rotation(2 * (i + 1) * (Math.PI * (s - 2)) / ((s - 2) * s), new Vector3d(0, 0, 1), new Point3d(0, 0, 0))); points.Add(p1); } VerticesOut = points; for (var i = 0; i < s; i++) { if (i != s - 1) { LineCurve pl = new LineCurve(points[i], points[i + 1]); segments.Add(pl); } else { LineCurve pl = new LineCurve(points[i], points[0]); segments.Add(pl); } } for (var i = 0; i < iter; i++) { List <LineCurve> frag = new List <LineCurve>(); for (var j = 0; j < segments.Count; j++) { Point3d[] p; segments[j].DivideByCount(3, true, out p); for (var k = 0; k < 2; k++) { points.Insert(j * 3 + k + 1, p[k + 1]); } for (var m = 0; m < 3; m++) { if (m + 1 + 3 * j == points.Count) { LineCurve pll = new LineCurve(points[m + 3 * j], points[0]); frag.Add(pll); } else { LineCurve pll = new LineCurve(points[m + 3 * j], points[m + 3 * j + 1]); frag.Add(pll); } } } int a = 0; int w = 0; LineCurve copie = new LineCurve(); for (var n = 0; n < frag.Count; n++) { if (n % 3 == 1) { a = a + 1; frag[n].Transform(Transform.Rotation(-Math.PI * ((s - 2) / s), new Vector3d(0, 0, 1), points[n + a + w - 1])); Point3d[] o; frag[n].DivideByCount(1, true, out o); Point3d np = new Point3d(o[1]); points.Insert(n + a + w, np); if (s > 3) { for (var zz = 0; zz < s - 3; zz++) { if (zz == 0) { LineCurve copy = new LineCurve(frag[n]); copie = copy; } Vector3d translation = new Vector3d(points[n + a + w - 1] - points[n + a + w]); copie.Transform(Transform.Translation(translation)); copie.Transform(Transform.Rotation(-Math.PI * ((s - 2) / s), new Vector3d(0, 0, 1), points[n + a + w])); Point3d[] yy; copie.DivideByCount(1, true, out yy); Point3d nps = new Point3d(yy[1]); points.Insert(n + a + w + 1, nps); w = w + 1; } } } } List <LineCurve> finall = new List <LineCurve>(); for (var q = 0; q < points.Count; q++) { if (q == points.Count - 1) { LineCurve plll = new LineCurve(points[q], points[0]); finall.Add(plll); } else { LineCurve plll = new LineCurve(points[q], points[q + 1]); finall.Add(plll); } } segments = finall; } CurvesOut = segments; VerticesOut = points; DA.SetDataList(0, CurvesOut); DA.SetDataList(1, VerticesOut); }
private Curve fromNorthRegulation(Apartment agOut, int stories) { Plot plot = agOut.Plot; Regulation regulation = new Regulation(stories); Polyline temp; plot.Boundary.TryGetPolyline(out temp); Curve[] plotArr = temp.GetSegments().Select(n => n.ToNurbsCurve()).ToArray(); //법규적용(일조에 의한 높이제한) double[] distanceFromNorth = new double[plotArr.Length]; for (int i = 0; i < plotArr.Length; i++) { Vector3d tempVector = new Vector3d(plotArr[i].PointAt(plotArr[i].Domain.T1) - plotArr[i].PointAt(plotArr[i].Domain.T0)); tempVector = tempVector / tempVector.Length; double moveDistance = 0; if (tempVector.X > 0 && plot.SimplifiedSurroundings[i] >= 0) { double tempSineFactor = System.Math.Abs(tempVector.X); double tempDistanceByRoad = plot.SimplifiedSurroundings[i] * 1000 / 2 * tempVector.Length / System.Math.Abs(tempVector.X); if (tempDistanceByRoad < regulation.DistanceFromNorth) { moveDistance = regulation.DistanceFromNorth - tempDistanceByRoad; } } distanceFromNorth[i] = moveDistance; } List <Point3d> distanceFromNorthPts = new List <Point3d>(); for (int i = 0; i < plotArr.Length; i++) { int h = (i - 1 + plotArr.Length) % plotArr.Length; int j = (i + 1 + plotArr.Length) % plotArr.Length; double distH = distanceFromNorth[h]; double distI = distanceFromNorth[i]; double distJ = distanceFromNorth[j]; if (distI == 0) { distanceFromNorthPts.Add(plotArr[i].PointAt(plotArr[i].Domain.T0)); distanceFromNorthPts.Add(plotArr[i].PointAt(plotArr[i].Domain.T1)); } else { Curve tempCurve = new LineCurve(plotArr[i].PointAt(plotArr[i].Domain.T0), plotArr[i].PointAt(plotArr[i].Domain.T1)); tempCurve.Transform(Transform.Translation(new Vector3d(0, -distI, 0))); var tempIntersect1 = Rhino.Geometry.Intersect.Intersection.CurveCurve(tempCurve, plotArr[h], 0, 0); var tempIntersect2 = Rhino.Geometry.Intersect.Intersection.CurveCurve(tempCurve, plotArr[j], 0, 0); if (tempIntersect1.Count > 0) { distanceFromNorthPts.Add(tempIntersect1[0].PointA); } else if (tempIntersect1.Count <= 0) { distanceFromNorthPts.Add(tempCurve.PointAt(tempCurve.Domain.T0)); } if (tempIntersect2.Count > 0) { distanceFromNorthPts.Add(tempIntersect2[0].PointA); } else if (tempIntersect2.Count <= 0) { distanceFromNorthPts.Add(tempCurve.PointAt(tempCurve.Domain.T1)); } } } distanceFromNorthPts.Add(distanceFromNorthPts[0]); Curve fromNorthCurve = (new Polyline(distanceFromNorthPts)).ToNurbsCurve(); return(fromNorthCurve); }