public static void ClosestCurveToNeedles(List <Curve> curves, List <Tuple <Point3d, Point3d> > needles, ref ClosestCurveT cp, List <string> mask = null, double sqTolerance = 20) { cp = new ClosestCurveT(); int i = 0; foreach (Tuple <Point3d, Point3d> pair in needles) { // Rhino.RhinoApp.WriteLine("hi"); var IndexAndParameter = CPCurvePoint(curves, pair.Item1, pair.Item2, sqTolerance);//how to define correct tolerance when beams are curved? //If at least one needle is found if (IndexAndParameter.Item1 != -1 || IndexAndParameter.Item3 != -1) { cp.ID0.Add(IndexAndParameter.Item1); cp.T0.Add(IndexAndParameter.Item2); cp.ID1.Add(IndexAndParameter.Item3); cp.T1.Add(IndexAndParameter.Item4); //Mask if (mask != null) { if (mask.Count == needles.Count) { cp.Mask.Add(mask[i]); } } }//if i++; }//for }
public static void ClosestCurves(List <Curve> L, double tolerance, ref ClosestCurveT t) { double toleranceEnds = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance; t = new ClosestCurveT(); HashSet <long> pairs = new HashSet <long>(); for (int i = 0; i < L.Count; i++) { for (int j = 0; j < L.Count; j++) { //In order to check the same pair again if (i == j) { continue; } long key = (i < j) ? MathUtil.GetKey(i, j) : MathUtil.GetKey(j, i); if (pairs.Contains(key)) { continue; } pairs.Add(key); //Check order bool checkEnds0 = L[i].PointAtStart.DistanceToSquared(L[j].PointAtStart) < toleranceEnds; //connected by ends bool checkEnds1 = L[i].PointAtStart.DistanceToSquared(L[j].PointAtEnd) < toleranceEnds; //connected by ends double t0, t1; if (checkEnds0) { t.T0.Add(0); t.T1.Add(0); t.ID0.Add(-i); t.ID1.Add(-j); t.L0.Add(L[i]); t.L1.Add(L[j]); } else if (checkEnds1) { t.T0.Add(0); t.T1.Add(1); t.ID0.Add(-i); t.ID1.Add(-j); t.L0.Add(L[i]); t.L1.Add(L[j]); } else { Rhino.Geometry.Intersect.CurveIntersections ci = Rhino.Geometry.Intersect.Intersection.CurveCurve(L[i], L[j], tolerance, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance); if (ci.Count > 0) { Line line = new Line(ci[0].PointA, ci[0].PointB); t0 = ci[0].ParameterA; t1 = ci[0].ParameterB; //Identify how lines are connected int EndSide0 = (t0 < toleranceEnds || t0 > 1 - toleranceEnds) ? -1 : 1; int EndSide1 = (t1 < toleranceEnds || t1 > 1 - toleranceEnds) ? -1 : 1; t.T0.Add(t0); t.T1.Add(t1); t.ID0.Add(i * EndSide0); t.ID1.Add(j * EndSide1); t.L0.Add(L[i]); t.L1.Add(L[j]); } //Touching - Not Touching //Print(EndSide0.ToString() + " " + EndSide1.ToString()); } } } }