protected override void SolveInstance(IGH_DataAccess DA) { Point3d M = Point3d.Origin; Point3d A = Point3d.Origin; Point3d B = Point3d.Origin; DA.GetData <Point3d>(0, ref M); DA.GetData <Point3d>(1, ref A); DA.GetData <Point3d>(2, ref B); LineCurve AB = new LineCurve(A, B); double t; AB.ClosestPoint(M, out t); DA.SetData(0, Utils.ClosestPointOnLine(M, A, B)); DA.SetData(1, AB.PointAt(t)); }
private static List <double> getUniqueParameter(List <Curve> baseCurve, Plot plot, out Curve perpendicularCurve, out List <int> indexOfTheParameter) { List <double> output = new List <double>(); ////////////////////////////////////////// BoundingBox boundaryBox = plot.Boundary.GetBoundingBox(false); double extendLength = boundaryBox.Corner(true, true, true).DistanceTo(boundaryBox.Corner(false, false, true)); Curve tempCurve = baseCurve[(int)(baseCurve.Count() / 2)]; Point3d centerPoint = tempCurve.PointAt(tempCurve.Domain.Mid); Vector3d centerPointPerpVector = tempCurve.TangentAt(tempCurve.Domain.Mid); centerPointPerpVector.Transform(Transform.Rotation(Math.PI / 2, Point3d.Origin)); perpendicularCurve = new LineCurve(centerPoint, centerPoint + centerPointPerpVector); double perpCurveStart = -extendLength; double perpCurveEnd = extendLength; perpendicularCurve = new LineCurve(perpendicularCurve.PointAt(perpCurveStart), perpendicularCurve.PointAt(perpCurveEnd)); List <Point3d> pointOnPerpCurve = new List <Point3d>(); foreach (Curve i in baseCurve) { double tempParameter; perpendicularCurve.ClosestPoint(i.PointAt(i.Domain.Mid), out tempParameter); pointOnPerpCurve.Add(perpendicularCurve.PointAt(tempParameter)); } List <Point3d> uniquePointOnPerpCurve = Point3d.CullDuplicates(pointOnPerpCurve, 1000).ToList(); List <double> uniquePointParameter = new List <double>(); foreach (Point3d i in uniquePointOnPerpCurve) { double tempParameter; perpendicularCurve.ClosestPoint(i, out tempParameter); uniquePointParameter.Add(tempParameter); } RhinoList <Point3d> rhinoUniquePointOnPerpCurve = new RhinoList <Point3d>(uniquePointOnPerpCurve); rhinoUniquePointOnPerpCurve.Sort(uniquePointParameter.ToArray()); uniquePointParameter.Sort(); List <int> tempIndexOfParameter = new List <int>(); foreach (Point3d i in rhinoUniquePointOnPerpCurve) { int index = pointOnPerpCurve.IndexOf(i); tempIndexOfParameter.Add(index); } /// indexOfTheParameter = tempIndexOfParameter; return(uniquePointParameter); }
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)); }
//채광방향 public static List <Curve> Lighting(Curve roadCenter, Plot plot, double aptAngle) { double d = 0; if (plot.PlotType != PlotTypes.상업지역) { if (plot.LegalMaxF <= 7) { d = 0.25; } else { d = 0.5; } } else { d = 0.25; } Curve basecurve = null; var cp = AreaMassProperties.Compute(plot.Boundary).Centroid; var basev = Vector3d.XAxis; basev.Rotate(aptAngle, Vector3d.ZAxis); var bounding = plot.Boundary.GetBoundingBox(false); basecurve = new LineCurve(cp - basev * bounding.Diagonal.Length / 2, cp + basev * bounding.Diagonal.Length / 2); List <Curve> result = new List <Curve>(); Curve last = roadCenter.DuplicateCurve(); double pheight = 3.3; double fheight = 2.8; int floor = plot.LegalMaxF; List <Curve> debug = new List <Curve>(); for (int i = 0; i < floor; i++) { var height = pheight + fheight * i; var distance = d * (height - pheight); var segments = roadCenter.DuplicateSegments(); for (int j = 0; j < segments.Length; j++) { var ps = segments[j].PointAtStart; var pe = segments[j].PointAtEnd; double ds = 0; double de = 0; basecurve.ClosestPoint(ps, out ds); basecurve.ClosestPoint(pe, out de); Vector3d vs = basecurve.PointAt(ds) - ps; Vector3d ve = basecurve.PointAt(de) - pe; vs.Unitize(); ve.Unitize(); var mp = segments[j].PointAtNormalizedLength(0.5); var ts = mp + vs; var te = mp + ve; if (roadCenter.Contains(ts) == PointContainment.Inside) { segments[j].Translate(vs * distance); } else if (roadCenter.Contains(te) == PointContainment.Inside) { segments[j].Translate(ve * distance); } segments[j].Translate(Vector3d.ZAxis * height); } List <Point3d> topoly = new List <Point3d>(); for (int k = 0; k < segments.Length; k++) { int j = (k + 1) % segments.Length; Line li = new Line(segments[k].PointAtStart, segments[k].PointAtEnd); Line lj = new Line(segments[j].PointAtStart, segments[j].PointAtEnd); double paramA; double paramB; var intersect = Rhino.Geometry.Intersect.Intersection.LineLine(li, lj, out paramA, out paramB, 0, false); topoly.Add(li.PointAt(paramA)); } topoly.Add(topoly[0]); var tempcurve = new PolylineCurve(topoly); var rotation = tempcurve.ClosedCurveOrientation(Vector3d.ZAxis); var selfintersection = Rhino.Geometry.Intersect.Intersection.CurveSelf(tempcurve, 0); var parameters = selfintersection.Select(n => n.ParameterA).ToList(); parameters.AddRange(selfintersection.Select(n => n.ParameterB)); var spl = tempcurve.Split(parameters); var f = NewJoin(spl); var merged = f.Where(n => n.ClosedCurveOrientation(Vector3d.ZAxis) == rotation).ToList(); debug.AddRange(merged); for (int j = merged.Count - 1; j >= 0; j--) { var tc = merged[j].DuplicateCurve(); tc.Translate(Vector3d.ZAxis * -tc.PointAtStart.Z); if (Curve.CreateBooleanDifference(tc, last).Length == 0) { last = tc; result.Add(merged[j]); } } } return(result); }