public void MakeRectanglesFromString(string parentLayerName, string input) { //if data is empty, return with nothing.. Add a note? Response myResponseAsObjects = Newtonsoft.Json.JsonConvert.DeserializeObject <Response>(input); List <Room> roomsSortedLargeToSmall = myResponseAsObjects.data.rooms.OrderBy(x => x.rectangleArea).ToList(); //int drawHeightTest = 0; int i = 0; foreach (Room myRoom in roomsSortedLargeToSmall) { Plane basePlane = Plane.WorldXY; //Plane tempBasePlane = new Plane(new Point3d(0, 0, drawHeightTest), new Vector3d(0, 0, 1)); //drawHeightTest += 24; Rectangle3d oneRectangle = new Rectangle3d(basePlane, myRoom.cornerA, myRoom.cornerB); LayerHelper.BakeObjectToLayer(oneRectangle.ToPolyline().ToPolylineCurve(), i + myRoom.room, parentLayerName); Color layerColor = System.Drawing.ColorTranslator.FromHtml(myRoom.roomColor); LayerHelper.ConfirmLayerColor(layerColor, i + myRoom.room, parentLayerName); i++; } RhinoDoc.ActiveDoc.Views.Redraw(); }
protected override void OnDynamicDraw(GetPointDrawEventArgs e) { base.OnDynamicDraw(e); if (From == Point3d.Unset) { return; } var cPlane = e.RhinoDoc.Views.ActiveView.ActiveViewport.ConstructionPlane(); Line = new Line(From, e.CurrentPoint); var yAxis = Vector3d.CrossProduct(Line.Direction, cPlane.ZAxis); if (Flip.CurrentValue) { yAxis.Reverse(); } var plane = new Plane(From, Line.Direction, yAxis); yAxis.Unitize(); var sideLength = Area.CurrentValue / Line.Length; Rectangle = new Rectangle3d(plane, Line.Length, sideLength); var color = e.RhinoDoc.Layers.CurrentLayer.Color; e.Display.DrawPolyline(Rectangle.ToPolyline(), color); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { //Create class instances Rectangle3d gardenBound = new Rectangle3d(); Brep carportGeom = new Brep(); Point3d accessPoint = new Point3d(); //Get Data if (!DA.GetData(0, ref gardenBound)) { return; } if (!DA.GetData(1, ref carportGeom)) { return; } if (!DA.GetData(2, ref accessPoint)) { return; } //Set properties PlotPlanning.ObjectModel.Carport carport = new ObjectModel.Carport(); carport.AccessPoint = accessPoint; carport.CarportGeom = carportGeom; carport.GardenBound = gardenBound.ToPolyline(); //Set data DA.SetData(0, carport); }
private void createParkingspace(Plane parkingspacePlane, LocalRules localRules, Boolean Flip) { //Create Parking rectangle Box = new Rectangle3d(parkingspacePlane, localRules.BoothWidth, localRules.BoothDepth); //Create ManeuveringArea Vector3d reverseVector = parkingspacePlane.YAxis; reverseVector.Reverse(); parkingspacePlane = new Plane(parkingspacePlane.Origin, parkingspacePlane.XAxis, reverseVector); if (Flip) { reverseVector.Unitize(); reverseVector = Vector3d.Multiply(localRules.ManeuveringArea + localRules.BoothDepth, -parkingspacePlane.YAxis); parkingspacePlane.Translate(reverseVector); } ManeuveringBox = new Rectangle3d(parkingspacePlane, localRules.BoothWidth, localRules.ManeuveringArea); //Create Parking Curves Center = Box.Center; Polyline polylineBox = Box.ToPolyline(); List <Curve> boxSegments = new List <Curve>(); boxSegments.Add(polylineBox.SegmentAt(1).ToNurbsCurve()); boxSegments.Add(polylineBox.SegmentAt(3).ToNurbsCurve()); if (Flip) { boxSegments.Add(polylineBox.SegmentAt(0).ToNurbsCurve()); } else { boxSegments.Add(polylineBox.SegmentAt(2).ToNurbsCurve()); } Curves = Curve.JoinCurves(boxSegments)[0]; }
// Start is called before the first frame update void Start() { var plane = new Rhino.Geometry.Plane(Point3d.Origin, Vector3d.ZAxis); var interval = new Interval(-0.5, 0.5); rect = new Rectangle3d(plane, interval, interval); var intervalR = new Interval(-5, 5); region = new Rectangle3d(plane, intervalR, intervalR); pts = RhinoWrapper.RandomPt(rect, numSphere); _relax = gameObject.AddComponent <Relax>(); spheres = new List <GameObject>(); var col = new Color(0.5f, 0, 0, 0.01f); for (int i = 0; i < pts.Count; i++) { var sphere = GameObject.CreatePrimitive(PrimitiveType.Quad); sphere.GetComponent <MeshRenderer>().material.color = Random.ColorHSV(1f, 1f, 1f, 1f, 0, 0); spheres.Add(sphere); } RhinoPreview.PolyLineShow(region.ToPolyline(), col, 0.3f); }
private static List <Polyline> DrawCorridor(Point3d anchor1, Point3d anchor2) { List <Polyline> corridors = new List <Polyline>(); Rectangle3d tempRect = RectangleTools.DrawP2PRect(anchor1, anchor2, CorridorDimension.TwoWayWidth); corridors.Add(tempRect.ToPolyline()); return(corridors); }
//THIS FUNCTION IS TEMPORARY. The function generates a box or a sweep. This determined by the linearity of the curve. public Brep MakeBrep() { Brep Geometri = new Brep(); double[] parameter = { 0.0, 2.2 }; Plane tempPlane = new Plane(elemLine.PointAtStart, elemLine.TangentAtStart); Ali.rotationVectorToPoint(elemLine.PointAtStart); Vector3d alignvector = Ali.Rotation; //Getting rotation angle double angle = Rhino.Geometry.Vector3d.VectorAngle(tempPlane.XAxis, alignvector, tempPlane); tempPlane.Rotate(angle, tempPlane.Normal, tempPlane.Origin); tempPlane.Translate(tempPlane.XAxis * Ali.OffsetY); tempPlane.Translate(tempPlane.YAxis * Ali.OffsetZ); Interval iz = new Interval(); Interval iy = new Interval(); Interval ix = new Interval(); double HalfWidth = rectSec.Width / 2; double HalfHeight = rectSec.Height / 2; iz = new Interval(-HalfHeight, HalfHeight); iy = new Interval(-HalfWidth, HalfWidth); ix = new Interval(0, elemLine.GetLength()); if (elemLine.IsLinear()) { Box boxen = new Box(tempPlane, iy, iz, ix); Geometri = boxen.ToBrep(); } else { SweepOneRail tempsweep = new SweepOneRail(); Rectangle3d rect = new Rectangle3d(tempPlane, iy, iz); rect.ToPolyline(); var sweep = tempsweep.PerformSweep(elemLine, rect.ToNurbsCurve()); Geometri = sweep[0]; } return(Geometri); }
private static List <Polyline> DrawCorridor(List <Point3d> anchor1, List <Point3d> anchor2) { List <Polyline> corridors = new List <Polyline>(); for (int i = 0; i < anchor1.Count; i++) { Rectangle3d tempRect = RectangleTools.DrawP2PRect(anchor1[i], anchor2[i], CorridorDimension.TwoWayWidth); corridors.Add(tempRect.ToPolyline()); } return(corridors); }
public void drawCircles() { for (int i = 0; i < nodePoints.Count; i++) { Plane plane = new Plane(nodePoints[i], Vector3d.ZAxis); Interval inter = new Interval(-cRadius, cRadius); var rect = new Rectangle3d(plane, inter, inter); //var circ = new Circle(nodePoints[i], cRadius); var poly = rect.ToPolyline(); drawingPolys.Add(poly); } }
public static Polyline ZigZagFromRectangle(Rectangle3d rec, double step, double scale = 0.9) { Polyline pline = new Polyline(); double step_ = Math.Max(step * 1.5, scale); Rectangle3d recShrink = new Rectangle3d(rec.Plane, new Interval(-(rec.Width * 0.5) + 0, (rec.Width * 0.5) - 0), new Interval(-(rec.Height * 0.5) + step_, (rec.Height * 0.5) - step_)); int divisions = (int)MathUtil.Constrain(recShrink.Width / step, 2, 500); divisions += divisions % 2; Polyline zz = PolylineUtil.ZigZag(recShrink.ToPolyline(), false, step); return(zz); }
public static Polyline[][] Square(Polyline[] contours, double size, double offset) { if (contours.Length == 0) { return(new Polyline[0][]); } var box = new BoundingBox(contours.SelectMany(p => p)); box.Inflate(offset); int countX = (int)Ceiling(box.Diagonal.X / size); int countY = (int)Ceiling(box.Diagonal.Y / size); double stepX = box.Diagonal.X / countX; double stepY = box.Diagonal.Y / countY; var rectangles = new List <Polyline>(countX * countY); for (double x = box.Min.X; x < box.Max.X; x += stepX) { for (double y = box.Min.Y; y < box.Max.Y; y += stepY) { var rect = new Rectangle3d(Plane.WorldXY, new Point3d(x + offset, y + offset, 0), new Point3d(x + stepX - offset, y + stepY - offset, 0)); rectangles.Add(rect.ToPolyline()); } } int layerCount = contours.Length; var layers = new Polyline[layerCount][]; Parallel.ForEach(Partitioner.Create(0, layerCount), range => { for (int i = range.Item1; i < range.Item2; i++) { // var skinOffset = Region.Offset(contours[i], offset); var skinOffset = contours[i]; if (!skinOffset.IsValid) { layers[i] = new Polyline[0]; continue; } var squares = rectangles.SelectMany(r => Region.Intersection(Enumerable.Repeat(r, 1), Enumerable.Repeat(skinOffset, 1))).ToArray(); //layers[i] = squares.Select(s => Region.Offset(s, offset)).Append(contours[i]).Where(p => p.IsValid).ToArray(); layers[i] = squares; } }); return(layers); }
private void drawBoxNet(ObjRef boxObjRef, RhinoDoc doc, bool shrinkToDimensions = false) { Vector3d widthHeightDepthVect = getWidthHeigthDepthVect(boxObjRef); Point3d bottomRightmostPoint; double effectiveNetThickness = shrinkToDimensions ? 0 : BIRCH_CM; RhinoList <Rectangle3d> rectList = generateNetRects(widthHeightDepthVect, out bottomRightmostPoint, thickness: effectiveNetThickness); Polyline polyline; Polyline[] explodedLines; Line jointLine; Point3d rightEdgeBottom, rightEdgeTop; // Draw the first finger leftmost before iterating jointLine = new Line(rectList[0].Corner(0), rectList[0].Corner(3)); polyline = generateFingerJoint(jointLine, BIRCH_CM); doc.Objects.AddPolyline(polyline); foreach (Rectangle3d rect in rectList) { // First draw fingers rightEdgeBottom = rect.Corner(1); rightEdgeTop = rect.Corner(2); jointLine = new Line(rightEdgeBottom, rightEdgeTop); // Draw on both sides of seam polyline = generateFingerJoint(jointLine, BIRCH_CM); doc.Objects.AddPolyline(polyline); // Then draw rectangle itself, explode, and remove seams polyline = rect.ToPolyline(); explodedLines = polyline.BreakAtAngles(Math.PI / 2); doc.Objects.AddPolyline(explodedLines[0]); doc.Objects.AddPolyline(explodedLines[2]); } // Finally, draw bottom rectangle bottomRightmostPoint += new Vector3d(BIRCH_CM / 2, 0, 0); Rectangle3d bottomRect = generateBottomRect(widthHeightDepthVect, bottomRightmostPoint, thickness: BIRCH_CM); doc.Objects.AddPolyline(bottomRect.ToPolyline()); doc.Views.Redraw(); }
public void DisplayRectangles(List <Member> members, double scalingFactorUnified, out List <Brep> oBreps) { Rectangle3d rectangle; List <Brep> breps = new List <Brep>(); Vector3d normal1; Vector3d normal2; Point3d point1; Point3d point2; Vector3d zPostive = new Vector3d(0, 0, 1); double thickness; double angle; for (int i = 0; i < members.Count; i++) { if (members[i].Force < 1e-13) { thickness = 1e-10; } else { thickness = members[i].Force * scalingFactorUnified; } //thickness = 1; point1 = members[i].FormLine.From; point2 = members[i].FormLine.To; normal1 = members[i].FormLine.Direction; normal1.Unitize(); normal1 = normal2 = normal1 * (thickness * 0.5); normal1.Rotate(0.5 * Math.PI, zPostive); normal2.Rotate(-0.5 * Math.PI, zPostive); point1 = Point3d.Add(point1, normal1); point2 = Point3d.Add(point2, normal2); Plane planeXY = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1)); angle = Vector3d.VectorAngle(new Vector3d(1, 0, 0), members[i].FormLine.Direction, planeXY); planeXY.Rotate(angle, new Vector3d(0, 0, 1)); rectangle = new Rectangle3d(planeXY, point1, point2); PolylineCurve curveRectangle = rectangle.ToPolyline().ToPolylineCurve(); breps.Add(Brep.CreatePlanarBreps(curveRectangle, 1e-14)[0]); } oBreps = breps; return; }
// Update is called once per frame void Update() { count++; if (count > 7) { pts.RemoveAt(0); pts.Add(RhinoWrapper.RandomPt(rect, 1)[0]); count = 0; } _relax.Compute(ref pts, 2, region.ToPolyline(), 0.05); var pos = pts.ToHost(); for (int i = 0; i < pos.Count; i++) { spheres[i].transform.position = pos[i]; } }
/// <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) { colors = new List <System.Drawing.Color>(); pNames = new List <string>(); pAreas = new List <double>(); List <Rectangle3d> rects = new List <Rectangle3d>(); GH_Structure <GH_Number> pData; GH_Structure <GH_Number> pWeights; List <Point3d> points = new List <Point3d>(); DataTree <double> mod_pData; DataTree <double> mod_pWeights; string message = "nothing"; bool optimized = false; int numMetrics = -1; DA.GetData(IN_numMetrics, ref numMetrics); DA.GetData(IN_reset, ref reset); DA.GetData(IN_run, ref run); DA.GetData(IN_mode, ref optimized); DA.GetDataList(IN_programNames, pNames); DA.GetDataList(IN_programAreas, pAreas); DA.GetDataTree(IN_programData, out pData); DA.GetDataList(IN_programColors, colors); DA.GetDataList(IN_pRects, rects); DA.GetDataTree(IN_pWeights, out pWeights); DA.GetData(IN_resolution, ref _resolution); DA.GetData(IN_radMultiplier, ref radiusMultiplier); DA.GetData(IN_showSOM, ref showSOM); DA.GetData(IN_SOMDisplay, ref display); DA.GetData(IN_DisplayLabels, ref displayText); if (run) { isRunning = true; } else { isRunning = false; } if (isRunning) { ExpireSolution(true); } var simpleNameTree = new DataTree <string>(); try { if (reset || SOM == null) { circles = new List <Polyline>(); points = new List <Point3d>(); radii = new List <double>(); gradientList = new List <System.Drawing.Color>(); for (int i = 0; i < rects.Count; i++) { points.Add(rects[i].Center); } for (int i = 0; i < pAreas.Count; i++) { var rad = Math.Sqrt(pAreas[i] / Math.PI); radii.Add(rad * radiusMultiplier); } mod_pData = new DataTree <double>(); mod_pWeights = new DataTree <double>(); for (int i = 0; i < pData.Paths.Count; i++) { var path = pData.get_Branch(i); for (int j = 0; j < path.Count; j++) { var p = new GH_Path(i); var prog = pData.get_DataItem(p, j).Value; mod_pData.Add(prog, new GH_Path(i)); } } for (int i = 0; i < pWeights.Paths.Count; i++) { var path = pWeights.get_Branch(i); for (int j = 0; j < path.Count; j++) { var p = new GH_Path(i); var weight = pWeights.get_DataItem(p, j).Value; mod_pWeights.Add(weight, new GH_Path(i)); } } //DA.SetDataTree(OUT_nodeWeights,mod_pWeights); SOM = new KMap(mod_pData, points, _resolution, mod_pWeights, numMetrics, 0.12, radii, 1.0, maximumIterations); SOM.applyProgramInputs(pNames.Count); SOM.outputNodesXY(); reset = false; } if (SOM.iter < maximumIterations) { if (InPreSolve) { Task <SolveResults> task = Task.Run(() => ComputeSOM(SOM), CancelToken); TaskList.Add(task); return; } if (!GetSolveResults(DA, out SolveResults result)) { result = ComputeSOM(SOM); SOM = result.Value; } message = string.Format("Runnning...{0}/{1} iterations", SOM.iter, maximumIterations); } else { message = "Done."; isRunning = false; run = false; ClearData(); } if (showSOM) { var nL = new List <double>(); SOM.nodeWeights.Clear(); for (int i = 0; i < SOM.nodeW.BranchCount; i++) { GH_Path path = SOM.nodeW.Path(i); int elementCount = SOM.nodeW.Branch(i).Count; double average = 0; for (int j = 0; j < elementCount; j++) { average += SOM.nodeW[path, j]; } average /= elementCount; nL.Add(average); //average value of all dims of a node } SOM.nodeWeights = nL; Remapper re = new Remapper(SOM.nodeWeights, SOM.nodePoints, pNames, pAreas, _resolution, optimized); var n = re.nodes; var _tree = re.programTree; ///silly name tree output as requested.. for (int i = 0; i < _tree.BranchCount; i++) { simpleNameTree.Add(_tree.Branch(i)[0].name.Split('_')[0], new GH_Path(i)); } //'tree' below is the sorted nodes corresponding to each program based on their BMU var tempTree = new DataTree <sNode>(); for (int i = 0; i < _tree.BranchCount; i++) { int localBCount = _tree.Branch(i).Count; var orderedBranch = _tree.Branch(i).OrderBy(c => c.multiplierStrength).ToList(); tempTree.AddRange(orderedBranch, new GH_Path(i)); } SOM.tree.Clear(); for (int i = 0; i < tempTree.BranchCount; i++) { var fPath = tempTree.Path(i); int localBCount = tempTree.Branch(i).Count; for (int j = 0; j < localBCount; j++) { Plane plane = new Plane(tempTree.Branch(i)[j].pos, Vector3d.ZAxis); Interval inter = new Interval(-_resolution * 0.5, _resolution * 0.5); var rect = new Rectangle3d(plane, inter, inter); var poly = rect.ToPolyline(); //circles.Add(poly); SOM.tree.Add(poly, new GH_Path(fPath)); } } //data for visualization var _points = new List <Point3d>(); SOM.m_pNames = new List <string>(); for (int i = 0; i < n.Count; i++) { var p = n[i].pos; var name = n[i].name; var multiplier = n[i].multiplierStrength; _points.Add(p); SOM.m_pNames.Add(name); } //color by gradient colors // for (int i = 0; i < nodeWeights.Count; i++) if (display == 1) { gradientList = new List <System.Drawing.Color>(); for (int i = 0; i < n.Count; i++) { var multiplier = n[i].multiplierStrength; var gColor = new ColorHSL(multiplier, 0, multiplier); var rgb = gColor.ToArgbColor(); gradientList.Add(rgb); } } else if (display == 2) { gradientList = new List <System.Drawing.Color>(); for (int i = 0; i < n.Count; i++) { var gColor = new ColorHSL(SOM.nodeWeights[i], SOM.nodeWeights[i], SOM.nodeWeights[i], SOM.nodeWeights[i]); var rgb = gColor.ToArgbColor(); gradientList.Add(rgb); } } for (int i = 0; i < SOM.m_pNames.Count; i++) { for (int j = 0; j < pNames.Count; j++) { var strippedName = SOM.RemoveNumbersSymbols(SOM.m_pNames[i]); if (strippedName == pNames[j]) { SOM.discreteCol.Add(colors[j]); } } } SOM.drawingPolys.Clear(); SOM.drawCircles(); circles = SOM.drawingPolys; } } catch (Exception e) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.ToString()); } DA.SetData(OUT_RunFeedback, message); DA.SetDataList(OUT_nodeWeights, SOM.nodeWeights); DA.SetDataTree(OUT_programTree, SOM.tree); DA.SetDataTree(OUT_programNames, simpleNameTree); }
/// <summary> /// The Method that generates Navigation Model for the PathFinding algorithm. /// </summary> /// <param name="searchAreaMesh"> A Mesh generated from the input Breps representing the search area.</param> /// <param name="context"> A Brep that represents context of the navigation model.</param> /// <param name="scaleFactor"> A double larger than 1.</param> /// <param name="cellSize"> A double for defining the size of the navigation model cells.</param> /// <param name="subdivision"> Number of subdivision of navigation model's cells.</param> /// <returns> A list of generic types. The first item of the list is a DataTree of Curves for visualizing the navigation model. /// The second item of the list is a DataTree of zeros and ones related to the location of the obstacles and walls in the /// navigation model, which is called wallData. /// The final item of the list is a custom object (WallInformation) that contains the wallData in it. This object will be used /// to generate and save a Json file from the wallData. /// </returns> private List <object> NavigationModel(Mesh searchAreaMesh, Brep context, double scaleFactor, double cellSize, int subdivision) { List <object> result = new List <object>(); int[,] wallDataArray; DataTree <int> wallData = new DataTree <int>(); DataTree <Polyline> navigationCells = new DataTree <Polyline>(); Rectangle3d cell = new Rectangle3d(); Brep scaledContext = new Brep(); scaledContext.Append(context); scaledContext.Transform(Transform.Scale(scaledContext.GetBoundingBox(true).Center, scaleFactor)); int cellCount = Convert.ToInt32(System.Math.Round((context.Edges[0].Domain[1] * scaleFactor) / cellSize)); // Array for serializing to Json wallDataArray = new int[cellCount, cellCount]; Plane modelOrigin = new Plane(scaledContext.GetBoundingBox(true).Corner(true, true, true), Vector3d.ZAxis); Point3d sample = new Point3d(); for (int i = 0; i < cellCount; i++) { for (int j = 0; j < cellCount; j++) { cell = new Rectangle3d(new Plane(new Point3d(modelOrigin.OriginX + (i * cellSize), modelOrigin.OriginY + (j * cellSize), modelOrigin.OriginZ), modelOrigin.Normal), cellSize, cellSize); navigationCells.Add(cell.ToPolyline(), new GH_Path(i)); int intersect = 0; for (double k = 0; k < (subdivision * 4); k++) { sample = cell.PointAt(k * 4 / (subdivision * 4)); if (Rhino.Geometry.Intersect.Intersection.MeshRay(searchAreaMesh, new Ray3d(sample, Vector3f.ZAxis)) >= 0) { intersect++; } } if (intersect >= subdivision * 4) { wallData.Add(0, new GH_Path(i)); wallDataArray[i, j] = 0; } else { wallData.Add(1, new GH_Path(i)); wallDataArray[i, j] = 1; } } } WallInformation wallInfo = new WallInformation(); wallInfo.WallData = wallDataArray; result.Add(navigationCells); result.Add(wallData); result.Add(wallInfo); return(result); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { //Create class instances string type = ""; bool carport = false; Rectangle3d gardenBound = new Rectangle3d(); Brep houseGeom = null; Point3d accessPoint = new Point3d(); int minAmount = 1; int maxAmount = 999; int offset = 1; //Get Data if (!DA.GetData(0, ref type)) { return; } if (!DA.GetData(1, ref carport)) { return; } if (!DA.GetData(2, ref gardenBound)) { return; } DA.GetData(3, ref houseGeom); // return; if (!DA.GetData(4, ref accessPoint)) { return; } if (!DA.GetData(5, ref minAmount)) { return; } if (!DA.GetData(6, ref maxAmount)) { return; } if (!DA.GetData(7, ref offset)) { return; } //Set properties PlotPlanning.ObjectModel.SingleFamily house = new ObjectModel.SingleFamily(type, carport, gardenBound.ToPolyline(), houseGeom, accessPoint, minAmount, maxAmount, offset); if (house.HouseGeom == null) { house.HouseGeom = ReadGeometry.ReadHouseGeometry(type); } //Set data DA.SetData(0, house); }
private static double maxRectDirection(Plot plot) { Polyline x; plot.Boundary.TryGetPolyline(out x); //parameters int gridResolution = 23; int angleResolution = 23; int ratioResolution = 5; int binarySearchIteration = 7; double ratioMaximum = 100; int gridSubResolution = 4; int angleSubResolution = 3; int ratioSubResolution = 4; int subIter = 4; double convergenceFactor = 1.1; double maxR = ratioMaximum; int binaryIter = binarySearchIteration; int rRes = ratioResolution; double alpha = 0.01; int edgeAngleNum = 5; //sub constants double gridDom = 0.3; double angleDom = 0.3; double ratioDom = 0.3; //plot Polyline xcurve = x; Curve plotCurve = xcurve.ToNurbsCurve(); //loop start parameters double areaMax = 0; double solWidth = 0; Point3d solPoint = new Point3d(0, 0, 0); double solR = 15; double solAngle = 0; //output List <Point3d> coreOri = new List <Point3d>(); List <Rectangle3d> coreShape = new List <Rectangle3d>(); //search space List <double> angles = new List <double>(); for (int i = 0; i < angleResolution; i++) { angles.Add(Math.PI * 2 * i / angleResolution); } List <Line> outlineSegments = x.GetSegments().ToList(); RhinoList <Line> outSegRL = new RhinoList <Line>(outlineSegments); List <double> outlineSegLength = outlineSegments.Select(n => n.Length).ToList(); outSegRL.Sort(outlineSegLength.ToArray()); outlineSegments = outSegRL.ToList(); outlineSegments.Reverse(); for (int i = 0; i < Math.Min(edgeAngleNum, outlineSegments.Count); i++) { Vector3d vector = outlineSegments[i].UnitTangent; if (vector.Y < 0) { vector.Reverse(); } double angleTemp = -Math.Acos(Vector3d.Multiply(Vector3d.XAxis, vector)); angles.Add(angleTemp); angles.Add(angleTemp + Math.PI / 2); } //loop for (int ang = 0; ang < angles.Count; ang++) { Polyline xClone = new Polyline(x); xClone.Transform(Transform.Rotation(angles[ang], new Point3d(0, 0, 0))); //find bounding box, grid dimensions var bBox = xClone.BoundingBox; Point3d minP = bBox.Min; Point3d maxP = bBox.Max; List <double> ressG = new List <double>(); ressG.Add(maxP.X - minP.X - 2 * alpha); ressG.Add(maxP.Y - minP.Y - 2 * alpha); List <double> resG = new List <double>(ressG.Select(val => val / gridResolution)); //1st search for (int i = 0; i < gridResolution + 1; i++) { //create lines Line lineY = new Line(new Point3d(minP.X + alpha + i * resG[0], minP.Y, 0), new Point3d(minP.X + alpha + i * resG[0], maxP.Y, 0)); Line lineX = new Line(new Point3d(minP.X, minP.Y + i + alpha * resG[1], 0), new Point3d(maxP.X, minP.Y + alpha + i * resG[1], 0)); //create mid points of segments List <Point3d> midsX = new List <Point3d>(intersectionMids(lineX, xClone)); List <Point3d> midsY = new List <Point3d>(intersectionMids(lineY, xClone)); List <Point3d> mids = new List <Point3d>(); foreach (Point3d j in midsX) { mids.Add(j); } foreach (Point3d j in midsY) { mids.Add(j); } foreach (Point3d j in mids) { //get max height and max width Line midlineY = new Line(new Point3d(j.X, minP.Y, 0), new Point3d(j.X, maxP.Y, 0)); Line midlineX = new Line(new Point3d(minP.X, j.Y, 0), new Point3d(maxP.X, j.Y, 0)); List <Point3d> widthP = new List <Point3d>(intersectionPoints(midlineX, xClone)); List <Point3d> heightP = new List <Point3d>(intersectionPoints(midlineY, xClone)); List <double> widthV = new List <double>(); List <double> heightV = new List <double>(); foreach (Point3d k in widthP) { widthV.Add(k.DistanceTo(j)); } foreach (Point3d k in heightP) { heightV.Add(k.DistanceTo(j)); } double maxWidth; double maxHeight; if (widthV.Count == 0) { maxWidth = 0; } else { maxWidth = widthV.Min() * 2; } if (heightV.Count == 0) { maxHeight = 0; } else { maxHeight = heightV.Min() * 2; } //binary search double minRatio = Math.Max(areaMax / maxWidth / maxWidth, 1 / maxR); double maxRatio = Math.Min(maxHeight * maxHeight / areaMax, maxR); double r = 1; if (minRatio < maxRatio) { for (int a = -rRes; a < rRes + 1; a++) { if (a < 0) { r = 1 / (1 + (1 / minRatio - 1) / Math.Pow(2, -a)); } else if (a == 1) { r = 1; } else { r = 1 + (maxRatio - 1) / Math.Pow(2, a); } //solution boundary List <double> minWidths = new List <double>(); minWidths.Add(Math.Sqrt(areaMax / r)); double minSolWidth = minWidths.Max(); double maxSolWidth = Math.Min(maxWidth, maxHeight / r); double searchWidth = (minSolWidth + maxSolWidth) / 2; double binRes = searchWidth / 2; //binary if (minSolWidth < maxSolWidth) { for (int b = 0; b < binaryIter; b++) { if (inCheck(j, searchWidth, r, xClone) == 1) { if (areaMax < searchWidth * searchWidth * r && searchWidth * searchWidth * r * 4 < PolygonArea(xcurve)) { areaMax = searchWidth * searchWidth * r; solWidth = searchWidth; solPoint = j; solR = r; solAngle = angles[ang]; } searchWidth += binRes; } else { searchWidth -= binRes; } binRes /= 2; } } } } } } } Rectangle3d ohGod = new Rectangle3d(Plane.WorldXY, new Point3d(solPoint.X - solWidth, solPoint.Y - solWidth * solR, 0), new Point3d(solPoint.X + solWidth, solPoint.Y + solWidth * solR, 0)); ohGod.Transform(Transform.Rotation(-solAngle, new Point3d(0, 0, 0))); //2nd search double solWidthNew = solWidth; Point3d solPointNew = solPoint; double solRNew = solR; double solAngleNew = solAngle; int token = 0; while (token < subIter) { gridDom /= convergenceFactor; angleDom /= convergenceFactor; ratioDom /= convergenceFactor; for (int ang = -angleSubResolution; ang < angleSubResolution + 1; ang++) { double searchAngle = solAngle + ang * Math.PI / 2 * angleDom / 2 / angleSubResolution; Polyline xCloneNew = new Polyline(x); xCloneNew.Transform(Transform.Rotation(searchAngle, new Point3d(0, 0, 0))); Curve xCloneNewCurve = xCloneNew.ToNurbsCurve(); //find bounding box, grid dimensions var bBox = xCloneNew.BoundingBox; Point3d minP = bBox.Min; Point3d maxP = bBox.Max; List <double> ressG = new List <double>(); ressG.Add(maxP.X - minP.X); ressG.Add(maxP.Y - minP.Y); List <double> resG = new List <double>(ressG.Select(val => val / (2 * gridSubResolution) * gridDom)); List <Point3d> mids = new List <Point3d>(); for (int i = -gridSubResolution; i < gridSubResolution + 1; i++) { for (int ii = -gridSubResolution; ii < gridSubResolution + 1; ii++) { Point3d solPointTemp = solPoint; //solPointTemp.Transform(Transform.Rotation(searchAngle, new Point3d(0, 0, 0))); Point3d gridPoint = new Point3d(solPointTemp.X + i * resG[0], solPointTemp.Y + ii * resG[1], 0); if (xCloneNewCurve.Contains(gridPoint) == PointContainment.Inside) { mids.Add(gridPoint); } } } foreach (Point3d j in mids) { //get max height and max width Line midlineY = new Line(new Point3d(j.X, minP.Y, 0), new Point3d(j.X, maxP.Y, 0)); Line midlineX = new Line(new Point3d(minP.X, j.Y, 0), new Point3d(maxP.X, j.Y, 0)); List <Point3d> widthP = new List <Point3d>(intersectionPoints(midlineX, xCloneNew)); List <Point3d> heightP = new List <Point3d>(intersectionPoints(midlineY, xCloneNew)); List <double> widthV = new List <double>(); List <double> heightV = new List <double>(); foreach (Point3d k in widthP) { widthV.Add(k.DistanceTo(j)); } foreach (Point3d k in heightP) { heightV.Add(k.DistanceTo(j)); } double maxWidth = widthV.Min(); double maxHeight = heightV.Min(); //binary search double r; for (int a = -ratioSubResolution; a < ratioSubResolution + 1; a++) { r = solR * (1 + a * ratioDom / ratioSubResolution); //solution boundary List <double> minWidths = new List <double>(); minWidths.Add(Math.Sqrt(areaMax / r)); double minSolWidth = minWidths.Max(); double maxSolWidth = Math.Min(maxWidth, maxHeight / r); double searchWidth = (minSolWidth + maxSolWidth) / 2; double binRes = searchWidth / 2; //binary if (minSolWidth < maxSolWidth) { for (int b = 0; b < binaryIter; b++) { if (inCheck(j, searchWidth, r, xCloneNew) == 1) { if (areaMax < searchWidth * searchWidth * r && searchWidth * searchWidth * r * 4 < PolygonArea(xcurve)) { areaMax = searchWidth * searchWidth * r; solWidthNew = searchWidth; solPointNew = j; solRNew = r; solAngleNew = searchAngle; } searchWidth += binRes; } else { searchWidth -= binRes; } binRes /= 2; } } } } } solWidth = solWidthNew; solPoint = solPointNew; solR = solRNew; solAngle = solAngleNew; token += 1; } solPoint.Transform(Transform.Rotation(-solAngle, new Point3d(0, 0, 0))); Rectangle3d ohGoditsworkingNew = new Rectangle3d(Plane.WorldXY, new Point3d(solPointNew.X - solWidthNew, solPointNew.Y - solWidthNew * solRNew, 0), new Point3d(solPointNew.X + solWidthNew, solPointNew.Y + solWidthNew * solRNew, 0)); ohGoditsworkingNew.Transform(Transform.Rotation(-solAngleNew, new Point3d(0, 0, 0))); Rectangle3d outlineRectangle = ohGoditsworkingNew; List <Point3d> pts = new List <Point3d>(outlineRectangle.ToPolyline()); Vector3d vectorT = Vector3d.Subtract(new Vector3d(pts[0]), new Vector3d(pts[1])); if (vectorT.Y < 0) { vectorT.Reverse(); } double outAngleTemp = -Math.Acos(Vector3d.Multiply(Vector3d.XAxis, Vector3d.Multiply(vectorT, 1 / vectorT.Length))); return(outAngleTemp); }
public static void PlaceDoorsAt(string schemeName) { string inputLayerPath = schemeName + "::EJLT Shapes"; string outputLayerPath = schemeName + "::Doors"; UnitSystem currentDocUnits = RhinoDoc.ActiveDoc.ModelUnitSystem; double unitSystemScaler = RhinoMath.UnitScale(UnitSystem.Feet, currentDocUnits); double doorW = 2.5 * unitSystemScaler; double doorH = 0.2 * unitSystemScaler; // get curves List <int> layerIndexs; List <Curve> curves = LayerHelper.GetCurvesFromChild(inputLayerPath, out layerIndexs); // explode curves List <Polyline> polies = new List <Polyline>(); List <Line[]> exploded = new List <Line[]>(); foreach (Curve c in curves) { Polyline poly; c.TryGetPolyline(out poly); polies.Add(poly); exploded.Add(poly.GetSegments()); } List <Point3d> centers = new List <Point3d>(); List <bool> vertical = new List <bool>(); // find overlapping curves, find center, find direction of lines for (int i = 0; i < polies.Count; i++) { foreach (Line line in exploded[i]) { for (int j = 0; j < polies.Count; j++) { if (i == j) { continue; // skip intersection check with current rectangle } foreach (Line otherline in exploded[j]) { Curve c1 = line.ToNurbsCurve(); Curve c2 = otherline.ToNurbsCurve(); // get all intersections var intersects = Intersection.CurveCurve(c1, c2, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, 0.1); if (intersects != null && intersects.Count > 0) { foreach (var inter in intersects) { if (inter.IsOverlap) // a overlap found { double length = inter.OverlapA.Length * c1.GetLength(); if (length > 3.5 * unitSystemScaler) // overlap is long enough { Point3d mid = c1.PointAt(inter.OverlapA.Mid); double mindis = 10000.0; foreach (Point3d oldpt in centers) { double distance = mid.DistanceTo(oldpt); if (distance < mindis) { mindis = distance; } } if (mindis > 1.0) // no duplicates { centers.Add(c1.PointAt(inter.OverlapA.Mid)); if (c1.PointAt(0).X == c1.PointAt(1).X) { vertical.Add(true); } else { vertical.Add(false); } } } } } } } } } } // draws rectangle for (int i = 0; i < centers.Count; i++) { if (vertical[i]) { Point3d corner = new Point3d(centers[i].X - doorH / 2, centers[i].Y - doorW / 2, 0.0); Rectangle3d rec = new Rectangle3d(new Plane(corner, Vector3d.ZAxis), doorH, doorW); LayerHelper.BakeObjectToLayer(rec.ToPolyline().ToPolylineCurve(), "Doors", schemeName); } else { Point3d corner = new Point3d(centers[i].X - doorW / 2, centers[i].Y - doorH / 2, 0.0); Rectangle3d rec = new Rectangle3d(new Plane(corner, Vector3d.ZAxis), doorW, doorH); LayerHelper.BakeObjectToLayer(rec.ToPolyline().ToPolylineCurve(), "Doors", schemeName); } } Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { //Create class instances Curve centreCrv = new PolylineCurve(); int floors = 1; double thickness = 1; double levelHeight = 1; Rectangle3d garden = new Rectangle3d(); Point3d accessPt = new Point3d(); //Get Data if (!DA.GetData(0, ref centreCrv)) { return; } if (!DA.GetData(1, ref floors)) { return; } if (!DA.GetData(2, ref thickness)) { return; } if (!DA.GetData(3, ref levelHeight)) { return; } if (!DA.GetData(4, ref garden)) { return; } if (!DA.GetData(5, ref accessPt)) { return; } //Set properties PlotPlanning.ObjectModel.MultiFamily house = new ObjectModel.MultiFamily(); house.Floors = floors; house.Thickness = thickness; house.LevelHeight = levelHeight; house.GardenBound = garden.ToPolyline(); house.AccessPoint = accessPt; //Create geometry. Brep[] b = Engine.Geometry.Compute.Sweep(centreCrv, thickness, 2); //Get and join all brep edges Curve[] En = b[0].DuplicateNakedEdgeCurves(true, true); Curve[] bound = Curve.JoinCurves(En); // TODO: make sure all the bounding curves are clockwise. This is to ensure extrution in the correct diection // For now I used a neg sign before extrution height.... Extrusion ex = Extrusion.Create(bound[0], -levelHeight * floors, true); if (centreCrv.IsClosed) { //Sort profiles by length. The longer curve will be the outer profile. The shorter the inner. Curve innerCrv = bound.ToList().OrderBy(x => x.GetLength()).First(); Extrusion exInner = Extrusion.Create(innerCrv, levelHeight * floors, true); Brep[] diff = Brep.CreateBooleanDifference(ex.ToBrep(), exInner.ToBrep(), ObjectModel.Tolerance.Distance); house.HouseGeom = diff[0]; } else { house.HouseGeom = ex.ToBrep(); } //Set data DA.SetData(0, house); }
public void Compute(int gridSize, int x_Ex, int y_Ex, int offsetValue, int offsetValue2, int reduceNum, int minRoomNum, Point3d center , ref List <Rhino.Geometry.Point3d> shapedGrid, ref PolylineCurve shapeCrv, ref Polyline offsetShapeCrv, ref Rectangle3d originalShape) { var grid = RhinoWrapper.MakeGrid(x_Ex, y_Ex, gridSize); var rectMain = RhinoWrapper.MakeRect(center, x_Ex, y_Ex, gridSize); var rectMainCrv = rectMain.ToPolyline().ToPolylineCurve(); originalShape = rectMain; //減らす部分の四角形をつくるための元のcorner var corners = new Rhino.Geometry.Point3d[4]; for (int i = 0; i < 4; i++) { corners[i] = rectMain.Corner(i); } //引くための四角形を作る範囲 var rectSub = RhinoWrapper.MakeRect(center, x_Ex, y_Ex, gridSize, offsetValue); var rectSub2 = RhinoWrapper.MakeRect(center, x_Ex, y_Ex, gridSize, offsetValue2); var populate = RhinoWrapper.RandomPt(rectSub, reduceNum); var randPts = populate.Where(pt => RhinoWrapper.IsInside(pt, rectSub2.ToPolyline()) == false).ToList(); //点が近いところにあるとオフセットがうまく機能しない。 for (int i = 0; i < randPts.Count; i++) { for (int j = 0; j < randPts.Count; j++) { if (i == j) { continue; } if (randPts[i].DistanceTo(randPts[j]) < gridSize * (minRoomNum + 1)) { randPts.RemoveAt(j); j--; } } } //Reduce Rectsを作ってる var reduceRects = new List <Rhino.Geometry.PolylineCurve>(); var planeXY = new Rhino.Geometry.Plane(Point3d.Origin, Vector3d.ZAxis); for (int i = 0; i < randPts.Count; i++) { var pc = new Rhino.Geometry.PointCloud(corners); int closestIdx = pc.ClosestPoint(randPts[i]); var reduceRect = new Rectangle3d(planeXY, randPts[i], corners[closestIdx]); var polyCrv = reduceRect.ToPolyline().ToPolylineCurve(); reduceRects.Add(polyCrv); } var shape = Curve.CreateBooleanDifference(rectMainCrv, reduceRects, 0.1); offsetShapeCrv = null; //正四角形でない形がでたとき if (shape.Length > 0) { shape[0].TryGetPolyline(out Polyline polyShape); //ref shapedGrid = grid.Where(pt => RhinoWrapper.IsInside(pt, polyShape)).ToList(); //ref shapeCrv = polyShape.ToPolylineCurve(); //ref var plane = new Rhino.Geometry.Plane(AreaMassProperties.Compute(shapeCrv).Centroid, Vector3d.ZAxis); shapeCrv.Offset(plane, (-gridSize * minRoomNum), 1, CurveOffsetCornerStyle.Sharp)[0].TryGetPolyline(out offsetShapeCrv); if (offsetShapeCrv == null) { offsetShapeCrv = new Rectangle3d(plane, 1, 1).ToPolyline(); } } else//正四角形が残ったとき。(ひくためのRectangleができない) { shapedGrid = grid.Where(pt => RhinoWrapper.IsInside(pt, rectMainCrv.ToPolyline())).ToList(); //ref shapeCrv = rectMainCrv.ToPolyline().ToPolylineCurve(); //ref var plane = new Rhino.Geometry.Plane(AreaMassProperties.Compute(shapeCrv).Centroid, Vector3d.ZAxis); shapeCrv.Offset(plane, (-gridSize * minRoomNum), 1, CurveOffsetCornerStyle.Sharp)[0].TryGetPolyline(out offsetShapeCrv); if (offsetShapeCrv == null) { offsetShapeCrv = new Rectangle3d(plane, 1, 1).ToPolyline(); } } }
/// <summary> /// Given an input manifest of named values between zero and one, generate a drawing. /// </summary> /// <param name="input"></param> public DrawingManifest(InputManifest input) { // Parse adjacent // Generate anchor points from input.Adjacent var position = 0.4 * input.Adjacent; var BottomLeft = new Point3d(0.5 - position, 0, 0); var TopLeft = new Point3d(0.5 - position, 1, 0); var BottomRight = new Point3d(0.5 + position, 0, 0); var TopRight = new Point3d(0.5 + position, 1, 0); // Generate interior points from input.Openings var pointCount = Convert.ToInt32(Math.Round(input.Openings * 9)) + 3; double step = 1.0 / pointCount; var leftPoints = new List <Point3d>(); var rightPoints = new List <Point3d>(); var r = new Random(Convert.ToInt32(input.Tutorial * 100)); var rotateL = Transform.Rotation((input.Parallel * 20) * (Math.PI / 180), Vector3d.ZAxis, new Point3d(input.Adjacent, input.Adjacent, 0)); var rotateR = Transform.Rotation((input.Parallel * -20) * (Math.PI / 180), Vector3d.ZAxis, new Point3d(1 - input.Adjacent, 1 - input.Adjacent, 0)); for (var i = 1; i < pointCount; i++) { var y = i * step; var x = r.NextDouble() * (input.Openings * 0.25); var ptLeft = new Point3d((0.5 - position - x), y, 0); var ptRight = new Point3d((0.5 + position + x), y, 0); ptLeft.Transform(rotateL); ptRight.Transform(rotateR); leftPoints.Add(ptLeft); rightPoints.Add(ptRight); } var leftEdgePoints = new List <Point3d>() { BottomLeft }; leftEdgePoints.AddRange(leftPoints); leftEdgePoints.Add(TopLeft); var rightEdgePoints = new List <Point3d>() { BottomRight }; rightEdgePoints.AddRange(rightPoints); rightEdgePoints.Add(TopRight); // Generate polylines var leftEdge = new Polyline(leftEdgePoints); var rightEdge = new Polyline(rightEdgePoints); // Push lines to output Debug.Add(RhinoPolylineToSvgar(leftEdge)); Debug.Add(RhinoPolylineToSvgar(rightEdge)); // Thicken polylines var thickenL = Transform.Translation(new Vector3d(-0.001, 0, 0)); var thickenR = Transform.Translation(new Vector3d(0.001, 0, 0)); var leftThicken = new Polyline(leftEdgePoints); leftThicken.Transform(thickenL); var rightThicken = new Polyline(rightEdgePoints); rightThicken.Transform(thickenR); Debug.Add(RhinoPolylineToSvgar(leftThicken)); Debug.Add(RhinoPolylineToSvgar(rightThicken)); var leftThicken2 = new Polyline(leftEdgePoints); leftThicken2.Transform(thickenL); leftThicken2.Transform(thickenL); var rightThicken2 = new Polyline(rightEdgePoints); rightThicken2.Transform(thickenR); rightThicken2.Transform(thickenR); Debug.Add(RhinoPolylineToSvgar(leftThicken2)); Debug.Add(RhinoPolylineToSvgar(rightThicken2)); // Offset polylines var offsetL = Transform.Translation(new Vector3d(-0.01, 0, 0)); var offsetR = Transform.Translation(new Vector3d(0.01, 0, 0)); var leftOffset = new Polyline(leftEdgePoints); leftOffset.Transform(offsetL); var rightOffset = new Polyline(rightEdgePoints); rightOffset.Transform(offsetR); Debug.Add(RhinoPolylineToSvgar(leftOffset)); Debug.Add(RhinoPolylineToSvgar(rightOffset)); var leftOffsetThicken = new Polyline(leftEdgePoints); leftOffsetThicken.Transform(offsetL); leftOffsetThicken.Transform(thickenL); var rightOffsetThicken = new Polyline(rightEdgePoints); rightOffsetThicken.Transform(offsetR); rightOffsetThicken.Transform(thickenR); Debug.Add(RhinoPolylineToSvgar(leftOffsetThicken)); Debug.Add(RhinoPolylineToSvgar(rightOffsetThicken)); //Edges.Add(RhinoPolylineToSvgar(leftEdge)); //Edges.Add(RhinoPolylineToSvgar(rightEdge)); // Extend line segments var lex = new List <Line>(); var rex = new List <Line>(); for (var i = 0; i < leftEdge.SegmentCount; i++) { var l = input.Disjoint * 0.15; var cL = leftEdge.SegmentAt(i); var cR = rightEdge.SegmentAt(i); var cLextended = new Line(cL.From, cL.To); cLextended.Extend(l, l); var cRextended = new Line(cR.From, cR.To); cRextended.Extend(l, l); var cLexA = new Line(cL.From, cLextended.From); var cLexB = new Line(cL.To, cLextended.To); var cRexA = new Line(cR.From, cRextended.From); var cRexB = new Line(cR.To, cRextended.To); lex.AddRange(new List <Line>() { cLexA, cLexB }); rex.AddRange(new List <Line>() { cRexA, cRexB }); } var movedLex = new List <Line>(); var movedRex = new List <Line>(); lex.ForEach(x => { var tx = Transform.Translation(new Vector3d(x.To - x.From) * 0.25); x.Transform(tx); movedLex.Add(x); }); rex.ForEach(x => { var tx = Transform.Translation(new Vector3d(x.To - x.From) * 0.25); x.Transform(tx); movedRex.Add(x); }); for (var i = 0; i < movedLex.Count; i++) { Debug.Add(RhinoPolylineToSvgar(new Polyline(new List <Point3d>() { movedLex[i].From, movedLex[i].To }))); Debug.Add(RhinoPolylineToSvgar(new Polyline(new List <Point3d>() { movedRex[i].From, movedRex[i].To }))); //var lexSegs = PolylineToDashedLine(new Polyline(new List<Point3d>() { movedLex[i].From, movedLex[i].To }), 0.15); //var rexSegs = PolylineToDashedLine(new Polyline(new List<Point3d>() { movedRex[i].From, movedRex[i].To }), 0.15); //var segs = new List<Polyline>(); //segs.AddRange(lexSegs); //segs.AddRange(rexSegs); //segs.ForEach(x => //{ // Debug.Add(RhinoPolylineToSvgar(x)); //}); //Extensions.Add(RhinoPolylineToSvgar(new Polyline(new List<Point3d>() { movedLex[i].From, movedLex[i].To }))); //Extensions.Add(RhinoPolylineToSvgar(new Polyline(new List<Point3d>() { movedRex[i].From, movedRex[i].To }))); } for (var i = 0; i < movedLex.Count; i += 2) { var crvA = movedLex[i]; var targetA = crvA.To.X > crvA.From.X ? new Point3d(rightEdge.SegmentAt(i / 2).To.X, crvA.To.Y, 0) : new Point3d(0, crvA.To.Y, 0); var crvB = movedLex[i + 1]; var targetB = crvB.To.X > crvB.From.X ? new Point3d(rightEdge.SegmentAt(i / 2).From.X, crvB.To.Y, 0) : new Point3d(0, crvB.To.Y, 0); var crvC = movedRex[i]; var targetC = crvC.To.X < crvC.From.X ? new Point3d(leftEdge.SegmentAt(i / 2).To.X, crvC.To.Y, 0) : new Point3d(1, crvC.To.Y, 0); var crvD = movedRex[i + 1]; var targetD = crvD.To.X < crvD.From.X ? new Point3d(leftEdge.SegmentAt(i / 2).From.X, crvD.To.Y, 0) : new Point3d(1, crvD.To.Y, 0); var ext = new List <Line>() { new Line(crvA.To, targetA), new Line(crvB.To, targetB), new Line(crvC.To, targetC), new Line(crvD.To, targetD) }; var allExtensions = new List <Polyline>(); ext.ForEach(x => { var scale = Transform.Scale(x.From, input.Disjoint); if (x.To.X > 0 && x.To.X < 1) { x.Transform(scale); } allExtensions.Add(new Polyline(new List <Point3d>() { x.From, x.To })); }); allExtensions.ForEach(x => { Debug.Add(RhinoPolylineToSvgar(x)); //PolylineToDashedLine(x, 0.15).ForEach(y => //{ // Debug.Add(RhinoPolylineToSvgar(y)); //}); //Extensions.Add(RhinoPolylineToSvgar(x)); }); } var largeLines = new List <Polyline>(); for (var i = 0; i < leftEdge.SegmentCount; i++) { var lc = leftEdge.SegmentAt(i); var rc = rightEdge.SegmentAt(i); var threshold = input.Largethreshold; if (lc.ToNurbsCurve().GetLength() > threshold / 2) { var largeC = new Line(lc.From, lc.To); largeC.ExtendThroughBox(new BoundingBox(new Point3d(0, 0, 0), new Point3d(1, 1, 1))); var largeCL = new Line(largeC.From, largeC.To); var largeCR = new Line(largeC.From, largeC.To); var moveR = Transform.Translation(new Vector3d(0.04, 0, 0)); var moveL = Transform.Translation(new Vector3d(-0.04, 0, 0)); largeCL.Transform(moveL); largeCR.Transform(moveR); largeLines.Add(new Polyline(new List <Point3d>() { new Point3d(largeCL.From.X - (0.04 * input.Parallel), largeCL.From.Y, 0), largeCL.To })); //largeLines.Add(new Polyline(new List<Point3d>() { largeC.From, largeC.To })); //largeLines.Add(new Polyline(new List<Point3d>() { new Point3d(largeCR.From.X + (0.04 * input.Parallel), largeCR.From.Y, 0), largeCR.To })); } if (rc.ToNurbsCurve().GetLength() > threshold / 2) { var largeC = new Line(rc.From, rc.To); largeC.ExtendThroughBox(new BoundingBox(new Point3d(0, 0, 0), new Point3d(1, 1, 1))); var largeCL = new Line(largeC.From, largeC.To); var largeCR = new Line(largeC.From, largeC.To); var moveR = Transform.Translation(new Vector3d(0.02, 0, 0)); var moveL = Transform.Translation(new Vector3d(-0.02, 0, 0)); largeCL.Transform(moveL); largeCR.Transform(moveR); //largeLines.Add(new Polyline(new List<Point3d>() { largeCL.From, new Point3d(largeCL.To.X - (0.04 * input.Parallel), largeCL.To.Y, 0) })); //largeLines.Add(new Polyline(new List<Point3d>() { largeC.From, largeC.To })); largeLines.Add(new Polyline(new List <Point3d>() { largeCR.From, new Point3d(largeCR.To.X + (0.04 * input.Parallel), largeCR.To.Y, 0) })); } } largeLines.ForEach(x => { PolylineToDashedLine(x, 0.02).ForEach(y => { Debug.Add(RhinoPolylineToSvgar(y)); }); //Parallels.Add(RhinoPolylineToSvgar(x)); }); var proportion = leftEdge.ToNurbsCurve().GetLength() / rightEdge.ToNurbsCurve().GetLength(); var sL = 0.25 * input.Porosity * proportion; var sR = 0.25 * input.Porosity * (1 / proportion); var iL = new Interval(-sL / 2, sL / 2); var iR = new Interval(-sR / 2, sR / 2); var anchorL = new Plane(new Point3d(0.2 * (1 - input.Adjacent), 0.3 * (1 - input.Adjacent), 0), Vector3d.ZAxis); var rectL = new Rectangle3d(anchorL, iL, iL); var rotL = Transform.Rotation((-90 * input.Parallel) * (Math.PI / 180), anchorL.Origin); var stretchL = Transform.Scale(anchorL, 1, 1 + (input.Porosity * proportion), 1); rectL.Transform(rotL); rectL.Transform(stretchL); var rectL2 = rectL.ToPolyline().Duplicate(); rectL2.Transform(Transform.Translation(rectL.Plane.YAxis * -0.2)); var rectL3 = rectL.ToPolyline().Duplicate(); rectL3.Transform(Transform.Translation(rectL.Plane.YAxis * -0.4)); var anchorR = new Plane(new Point3d(1 - (0.2 * (1 - input.Adjacent)), 1 - (0.3 * (1 - input.Adjacent)), 0), Vector3d.ZAxis); var rectR = new Rectangle3d(anchorR, iR, iR); var rotR = Transform.Rotation((-90 * input.Parallel) * (Math.PI / 180), anchorR.Origin); var stretchR = Transform.Scale(anchorR, 1, 1 + (input.Porosity * (1 / proportion)), 1); rectR.Transform(rotR); rectR.Transform(stretchR); var rectR2 = rectR.ToPolyline().Duplicate(); rectR2.Transform(Transform.Translation(rectR.Plane.YAxis * 0.2)); var rectR3 = rectR.ToPolyline().Duplicate(); rectR3.Transform(Transform.Translation(rectR.Plane.YAxis * 0.4)); var allRects = new List <Polyline>() { rectL.ToPolyline(), rectL2, rectL3, rectR.ToPolyline(), rectR2, rectR3 }; var allRectsThickened = new List <Polyline>(allRects); allRectsThickened.ForEach(x => { var left = new Polyline(x); left.Transform(thickenL); allRects.Add(left); var right = new Polyline(x); right.Transform(thickenR); allRects.Add(right); }); var mPlane = Plane.WorldZX; mPlane.Origin = new Point3d(0.5, 0.5, 0); var mirror = Transform.Mirror(mPlane); allRects.ForEach(x => { Debug.Add(RhinoPolylineToSvgar(x)); //Holes.Add(RhinoPolylineToSvgar(x)); var mx = x.Duplicate(); mx.Transform(mirror); Debug.Add(RhinoPolylineToSvgar(mx)); //Holes.Add(RhinoPolylineToSvgar(mx)); }); }