public void UnitCircle_DisjointCurve_CurveUnchanged() { Curve unitCircle = new Circle(Point3d.Origin, 0.5).ToNurbsCurve(); Curve disjointCurve = new LineCurve(new Point2d(5, 5), new Point2d(5, 10)); double originalLength = disjointCurve.GetLength(); Curve resultCurve = Logic.Transformations.Curves.TrimWithClosedCurve(unitCircle, disjointCurve); Assert.AreEqual(originalLength, resultCurve.GetLength()); }
// Rh Line capture public Line LineToSpeckle(LineCurve line, string units = null) { var u = units ?? ModelUnits; var sLine = new Line(PointToSpeckle(line.PointAtStart, u), PointToSpeckle(line.PointAtEnd, u), u) { domain = IntervalToSpeckle(line.Domain) }; sLine.length = line.GetLength(); var box = new RH.Box(line.GetBoundingBox(true)); sLine.bbox = BoxToSpeckle(box, u); return(sLine); }
private static List <Curve> MakeAxisLine(Polyline boundary, double axisAngle, out Point3d centerPt) { Vector3d baseAxis = Plane.WorldXY.XAxis; baseAxis.Transform(Transform.Rotation(axisAngle, Plane.WorldXY.Origin)); Vector3d perpendicularAxis = baseAxis; perpendicularAxis.Transform(Transform.Rotation(Math.PI / 2, Plane.WorldXY.Origin)); centerPt = boundary.CenterPoint(); BoundingBox tempBounding = new BoundingBox(new List <Point3d>(boundary)); LineCurve diagonal = new LineCurve(tempBounding.Max, tempBounding.Min); double axisLength = diagonal.GetLength() / 2; LineCurve test1 = new LineCurve(centerPt - baseAxis * axisLength, centerPt + baseAxis * axisLength); LineCurve test2 = new LineCurve(centerPt - perpendicularAxis * axisLength, centerPt + perpendicularAxis * axisLength); List <Curve> testLineSet = new List <Curve>(); testLineSet.Add(test1); testLineSet.Add(test2); return(testLineSet); }
IEnumerable <SlitPoint> SlitPoints(Curve curve, LineCurve line) { if (curve.IsClosed) { var points = Rhino.Geometry.Intersect.Intersection.CurveCurve(line, curve, Unit, Unit); foreach (var item in points) { if (item.IsOverlap) { if (item.OverlapA.T0 < item.OverlapA.T1) { yield return(new SlitPoint(item.OverlapA.T0, item.PointA)); } else { yield return(new SlitPoint(item.OverlapA.T1, item.PointA2)); } } else { yield return(new SlitPoint(item.ParameterA, item.PointA)); } } if (points.Count % 2 == 1) { yield return(new SlitPoint(line.GetLength(), line.PointAtEnd)); } } else { foreach (var item in Rhino.Geometry.Intersect.Intersection.CurveCurve(line, curve, Unit, Unit)) { var unit = line.Domain.Length / line.GetLength(); var dir = line.Line.Direction; dir.Unitize(); if (item.IsOverlap) { if (item.OverlapA.T0 < item.OverlapA.T1) { yield return(new SlitPoint(item.OverlapA.T0 - unit, item.PointA - dir)); yield return(new SlitPoint(item.OverlapA.T0 + unit, item.PointA + dir)); } else { yield return(new SlitPoint(item.OverlapA.T1 - unit, item.PointA2 - dir)); yield return(new SlitPoint(item.OverlapA.T1 + unit, item.PointA2 + dir)); } } else { yield return(new SlitPoint(item.ParameterA - unit, item.PointA - dir)); yield return(new SlitPoint(item.ParameterA + unit, item.PointA + dir)); } } } }
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 Dictionary <int, List <Mesh> > GenerateJointMeshes(bool label = true) { JointMeshes.Clear(); JointArmLabel.Clear(); var separateJointMeshes = new Dictionary <int, List <Mesh> >(); var jointArmCounter = new Dictionary <int, int>(); var jointCorePoints = new Dictionary <int, List <double[]> >(); for (int v = 0; v < Vertices.Count; v++) { separateJointMeshes[v] = new List <Mesh>(); jointCorePoints[v] = new List <double[]>(); jointArmCounter[v] = 1; } foreach (Tuple <int, int> e in Edges) { if (!RodMeshes.ContainsKey(e)) { continue; } Curve c = new LineCurve(Vertices[e.Item1], Vertices[e.Item2]); double len = c.GetLength(); if (len == 0) { throw new Exception("Joint not created. Joint lengths greater than rod length. Try reducing joint lengths or radius."); } Curve startCurve; Curve endCurve; try { startCurve = c.Trim(CurveEnd.End, len - (Offsets[e] + JointLength)); endCurve = c.Trim(CurveEnd.Start, len - (Offsets[Tuple.Create(e.Item2, e.Item1)] + JointLength)); if (startCurve == null || endCurve == null) { throw new Exception(); } } catch { throw new Exception("Joint not created. Joint lengths greater than rod length. Try reducing joint lengths or radius."); } // Convex hull points var vector = Point3d.Subtract(Vertices[e.Item2], Vertices[e.Item1]); vector.Unitize(); Polyline outerPoly; var outerProfile = GetProfile(OuterWallRadius, vector); outerProfile.TryGetPolyline(out outerPoly); foreach (var l in outerPoly.Skip(1)) { jointCorePoints[e.Item1].Add(new double[] { l.X + Vertices[e.Item1].X, l.Y + Vertices[e.Item1].Y, l.Z + Vertices[e.Item1].Z }); jointCorePoints[e.Item2].Add(new double[] { l.X + Vertices[e.Item2].X, l.Y + Vertices[e.Item2].Y, l.Z + Vertices[e.Item2].Z }); } // Create hollow joint arms var startMesh = GenerateJointArm(Vertices[e.Item1], vector, startCurve.GetLength(), Offsets[e]); var endMesh = GenerateJointArm(Vertices[e.Item2], vector, -endCurve.GetLength(), -Offsets[Tuple.Create(e.Item2, e.Item1)]); separateJointMeshes[e.Item1].Add(startMesh); separateJointMeshes[e.Item2].Add(endMesh); if (label) { // Create joint label var startLabel = GenerateJointArmLabel(Vertices[e.Item1], vector, e.Item1.ToString() + ((char)(jointArmCounter[e.Item1] + 64)).ToString(), startCurve.GetLength()); var endLabel = GenerateJointArmLabel(Vertices[e.Item2], vector, e.Item2.ToString() + ((char)(jointArmCounter[e.Item2] + 64)).ToString(), -endCurve.GetLength()); jointArmCounter[e.Item1]++; jointArmCounter[e.Item2]++; if (startLabel != null) { separateJointMeshes[e.Item1].Add(startLabel); } if (endLabel != null) { separateJointMeshes[e.Item2].Add(endLabel); } } } foreach (KeyValuePair <int, List <double[]> > kvp in jointCorePoints) { try { var scaling = Math.Floor(1000 / kvp.Value.SelectMany(p => p).Max()); var convHullRes = ConvexHull.Create(kvp.Value.Select(p => p.Select(pi => pi * scaling).ToArray()).ToList()); var hullPoints = convHullRes.Result.Points.ToList(); var hullFaces = convHullRes.Result.Faces.ToList(); var newMesh = new Mesh(); newMesh.Vertices.AddVertices(hullPoints.Select(p => new Point3d(p.Position[0] / scaling, p.Position[1] / scaling, p.Position[2] / scaling))); newMesh.Faces.AddFaces(hullFaces.Select(f => new MeshFace(hullPoints.IndexOf(f.Vertices[0]), hullPoints.IndexOf(f.Vertices[1]), hullPoints.IndexOf(f.Vertices[2])))); newMesh.Normals.ComputeNormals(); newMesh.UnifyNormals(); newMesh.Normals.ComputeNormals(); newMesh.Compact(); separateJointMeshes[kvp.Key].Insert(0, newMesh); // Add conv hull to beginning } catch { } } foreach (KeyValuePair <int, List <Mesh> > kvp in separateJointMeshes) { if (kvp.Value.Count > 0) { var mesh = kvp.Value.First(); foreach (var m in kvp.Value.Skip(1)) { mesh.Append(m); } mesh.Weld(Tolerance); JointMeshes[kvp.Key] = new List <Mesh>() { mesh }; } } return(JointMeshes); }