////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public Polyline ClosetPly(List <Line> C, bool B) //////////////将线段组闭合成多段线 { List <Point3d> last = new List <Point3d>(); for (int i = 0; i < C.Count - 1; i++) { Point3d pt1; Point3d pt2; if (i == 0) { ViperClass.ClosedPt(C[0], C[C.Count - 1], out pt1, out pt2); last.Add((pt1 + pt2) / 2); } ViperClass.ClosedPt(C[i], C[i + 1], out pt1, out pt2); last.Add((pt1 + pt2) / 2); } last.Add(last[0]); if (B == false) //////不闭合的情况 { Vector3d vc = Point3d.Subtract(C[C.Count - 1].From, C[C.Count - 1].To); //////该方向用于判断最后那个点的位置 last[0] = C[0].From; if (last[1].DistanceTo(C[0].From) < last[1].DistanceTo(C[0].To)) ////最远 { last[0] = C[0].To; } last[last.Count - 1] = C[C.Count - 1].From; if (last[last.Count - 2].DistanceTo(C[C.Count - 1].From) < last[last.Count - 2].DistanceTo(C[C.Count - 1].To))///最远 { last[last.Count - 1] = C[C.Count - 1].To; } } return(new Polyline(last)); }
/// <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) { Curve polyline = null; if (!DA.GetData(0, ref polyline)) { return; } List <Point3d> pts = ViperClass.Ptsss(polyline); List <Line> lines = new List <Line>(); if (pts.Count > 3) { for (int i = 0; i < pts.Count; i++) { for (int j = i + 2; j < pts.Count; j++) { if (i == 0 && j == pts.Count - 1) { break; } Line l = new Line(pts[i], pts[j]); lines.Add(l); } } } DA.SetDataList(0, lines); }
/// <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) { Curve curve = null; if (!DA.GetData(0, ref curve)) { return; } Polyline polyline = new Polyline(); curve.TryGetPolyline(out polyline); List <Point3d> pts = new List <Point3d>(); List <Line> lines = new List <Line>(); for (int q = 0; q < polyline.SegmentCount; q++) { lines.Add(polyline.SegmentAt(q)); pts.Add(polyline.SegmentAt(q).From); pts.Add(polyline.SegmentAt(q).To); } pts = pts.Distinct().ToList(); bool test = true; for (int k = 0; k < lines.Count; k++) { if (!ViperClass.SameSide(lines[k], pts)) { test = false; break; } } DA.SetData(0, test); }
/// <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) { List <Curve> polylineCurves = new List <Curve>(); double curveTolerance = 0; double joinTolerance = 0; if (!DA.GetDataList(0, polylineCurves)) { return; } if (!DA.GetData(1, ref curveTolerance)) { return; } if (!DA.GetData(2, ref joinTolerance)) { return; } List <Curve> curves = new List <Curve>(); for (int i = 0; i < polylineCurves.Count; i++) { Curve c = polylineCurves[i]; List <double> tt = ViperClass.curveKnot(c); Curve[] cs = c.Split(tt); curves.AddRange(cs); } List <Curve> resultCr = ViperClass.deleteSameCurve(curves, curveTolerance); Curve[] joinCurves = Curve.JoinCurves(resultCr.ToArray(), joinTolerance); DA.SetDataList(0, joinCurves); }
/// <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) { ///////////////////////////////////////////////////////////////////////////////////////////////////声明变量 List <Curve> c = new List <Curve>(); double t1 = 0; double t2 = 0; ///////////////////////////////////////////////////////////////////////////////////////////////////检测输入端是否合理 if (!DA.GetDataList(0, c)) { return; } if (!DA.GetData(1, ref t1)) { return; } if (!DA.GetData(2, ref t2)) { return; } DataTree <Curve> last = new DataTree <Curve>(); DataTree <Point3d> collects = ViperClass.EmptyTree(c.Count); int index = 0; int branch = DA.Iteration; for (int i = 0; i < c.Count; i++) { for (int q = i + 1; q < c.Count; q++) { Rhino.Geometry.Intersect.CurveIntersections result = Rhino.Geometry.Intersect.Intersection.CurveCurve(c[i], c[q], t1, t2); if (result.Count > 0) ////有交集 { for (int k = 0; k < result.Count; k++) ////记录每次相交的t值并分别赋值给两曲线 { collects.Branch(i).Add((result[k].PointA)); collects.Branch(q).Add((result[k].PointB)); } } } } ///////////////////////////////////////////////////////////////////////////////////////////////// for (int i = 0; i < c.Count; i++) { if (collects.Branch(i).Count == 0) { last.Add(c[i], new GH_Path(0, branch, index)); index++; continue; } last.AddRange(ViperClass.SplitByPts(c[i], collects.Branch(i).ToList()), new GH_Path(0, branch, index)); index++; } DA.SetDataTree(0, last); }
/// <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) { Curve polylineCurve = null; if (!DA.GetData(0, ref polylineCurve)) { return; } Curve[] seg = polylineCurve.DuplicateSegments(); List <Line> right = new List <Line>();//////分离出线段部分 for (int i = 0; i < seg.Length; i++) { if (seg[i].IsLinear()) { Line test = new Line(seg[i].PointAtStart, seg[i].PointAtEnd); right.Add(test); } } List <Point3d> last = new List <Point3d>();////重新计算交点 Point3d pt1 = Point3d.Unset; Point3d pt2 = Point3d.Unset; if (polylineCurve.IsClosed)////闭合曲线 { ViperClass.ClosedPt(right[0], right[right.Count - 1], out pt1, out pt2); last.Add((pt1 + pt2) / 2); for (int i = 0; i < right.Count - 1; i++) { ViperClass.ClosedPt(right[i], right[i + 1], out pt1, out pt2); last.Add((pt1 + pt2) / 2); } last.Add(last[0]); } if (!polylineCurve.IsClosed)////不闭合曲线 { last.Add(right[0].From); for (int i = 0; i < right.Count - 1; i++) { ViperClass.ClosedPt(right[i], right[i + 1], out pt1, out pt2); last.Add((pt1 + pt2) / 2); } last.Add(right[right.Count - 1].To); } DA.SetData(0, new Polyline(last)); }
/// <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) { Curve c1 = null; Curve c2 = null; List <Point3d> pts = new List <Point3d>(); Plane pln = Plane.Unset; if (!DA.GetData <Curve>(0, ref c1) || !DA.GetData <Curve>(1, ref c2) || !DA.GetDataList <Point3d>(2, pts) || !DA.GetData <Plane>(3, ref pln)) { return; } List <Point3d> last = new List <Point3d>(); List <bool> last2 = new List <bool>(); foreach (Point3d pt in pts) { if (Between) { if ((ViperClass.CurveSide(c1, pt, pln) == -1 && ViperClass.CurveSide(c2, pt, pln) == 1) || (ViperClass.CurveSide(c1, pt, pln) == 1 && ViperClass.CurveSide(c2, pt, pln) == -1)) { last.Add(pt); last2.Add(true); } else { last2.Add(false); } } else { if ((ViperClass.CurveSide(c1, pt, pln) == -1 && ViperClass.CurveSide(c2, pt, pln) == 1) || (ViperClass.CurveSide(c1, pt, pln) == 1 && ViperClass.CurveSide(c2, pt, pln) == -1) || ViperClass.CurveSide(c1, pt, pln) == 0 || ViperClass.CurveSide(c2, pt, pln) == 0) { last.Add(pt); last2.Add(true); } else { last2.Add(false); } } } DA.SetDataList(0, last); DA.SetDataList(1, last2); }
/// <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) { Curve railCurve = null; double radius = 0; int segments = 0; double angle = 0; if (!DA.GetData(0, ref railCurve)) { return; } if (!DA.GetData(1, ref radius)) { return; } if (!DA.GetData(2, ref segments)) { return; } if (!DA.GetData(3, ref angle)) { return; } /////////////////////////////////////////////////// Curve x = railCurve; double y = radius; int n = segments; Vector3d vc = x.TangentAtStart; Plane pl = new Plane(x.PointAtStart, vc); Polyline ply = ViperClass.CreatePolyline(pl, y, n); ply.Transform(Transform.Rotation(angle, pl.ZAxis, pl.Origin)); NurbsCurve nc = ply.ToNurbsCurve(); SweepOneRail swp = new SweepOneRail(); Brep[] bs = swp.PerformSweep(x, nc); DA.SetDataList(0, bs); }
/// <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) { ///////////////////////////////////////////////////////////////////////////////////////////////////声明变量 Curve c1 = null; Curve c2 = null; ///////////////////////////////////////////////////////////////////////////////////////////////////检测输入端是否合理 if (!DA.GetData(0, ref c1)) { return; } if (!DA.GetData(1, ref c2)) { return; } List <Point3d> ptcor1 = ViperClass.Ptsss(c1); List <Point3d> ptcor2 = ViperClass.Ptsss(c2); Polyline polylineA = new Polyline(ptcor1); Polyline polylineB = new Polyline(ptcor2); List <double> angles1 = new List <double>(); List <double> angles2 = new List <double>(); List <double> ag1 = new List <double>(); List <double> ag2 = new List <double>(); int n1 = polylineA.SegmentCount; int n2 = polylineB.SegmentCount; bool flag = false; if (n1 == n2) { flag = true; Line[] ls1 = polylineA.GetSegments(); Line[] ls2 = polylineB.GetSegments(); for (int i = 0; i < n1; i++) { if (i == n1 - 1) { Line la11 = ls1[i]; Line la22 = ls1[0]; double aa = Math.Round(ViperClass.getangle(la11, la22), 3); angles1.Add(aa); Line lb11 = ls2[i]; Line lb22 = ls2[0]; double bb = Math.Round(ViperClass.getangle(lb11, lb22), 3); angles2.Add(bb); continue; } Line la1 = ls1[i]; Line la2 = ls1[i + 1]; double a = Math.Round(ViperClass.getangle(la1, la2), 3); angles1.Add(a); Line lb1 = ls2[i]; Line lb2 = ls2[i + 1]; double b = Math.Round(ViperClass.getangle(lb1, lb2), 3); angles2.Add(b); } angles1.Sort(); angles2.Sort(); for (int i = 0; i < n1; i++) { if (angles1[i] != angles2[i]) { flag = false; break; } } } DA.SetData(0, flag); }
/// <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) { List <Point3d> points = new List <Point3d>(); Point3d point = new Point3d(); bool reverse = false; if (!DA.GetDataList(0, points)) { return; } if (!DA.GetData(1, ref point)) { return; } if (!DA.GetData(2, ref reverse)) { return; } List <Point3d> x = points; bool y = reverse; ////////////////////////////////////////////////////// Point3d c = ViperClass.center(x); if (point != Point3d.Unset)////如果指定点则以指定点为中心 { c = point; } Plane pl; Plane.FitPlaneToPoints(x, out pl); pl.Origin = c; double dist = 0;///以所有点离中心点距离的平均值为半径 for (int i = 0; i < x.Count; i++) { dist += c.DistanceTo(x[i]); } Circle cir = new Circle(pl, dist / x.Count); /////////////////////////////////////////////////// List <double> ts = new List <double>(); List <double> ts2 = new List <double>(); for (int i = 0; i < x.Count; i++) { double t; cir.ClosestParameter(x[i], out t); ts.Add(t); ts2.Add(t); } ts.Sort(); if (reverse) { ts.Reverse(); } List <int> index = new List <int>();///找出对应的索引值 for (int i = 0; i < x.Count; i++) { for (int j = 0; j < x.Count; j++) { if (ts[i] == ts2[j]) { index.Add(j); ts2[j] = double.PositiveInfinity; break; } } } List <Point3d> ptnew = new List <Point3d>(); for (int i = 0; i < x.Count; i++) { ptnew.Add(x[index[i]]); } DA.SetDataList(0, ptnew); DA.SetDataList(1, index); }