Exemplo n.º 1
0
        //public VariableDivide() { }
        public static VariableDivide Divide(Curve crv, List <double> distanceList, int rep)
        {
            VariableDivide vd = new VariableDivide();

            if (distanceList.Count == 0)
            {
                return(null);
            }

            if (rep > 2 | rep < 0)
            {
                rep = 0;
            }
            //Dictionary<int, List<double>>.ValueCollection values = dictDistances.Values;

            crv.Domain = new Interval(0, crv.GetLength());
            double t1  = crv.Domain.T1;
            double tol = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;

            int i, j;

            i = j = -1;

            List <Curve>   crvList = new List <Curve>();
            List <Point3d> ptList  = new List <Point3d>()
            {
                crv.PointAtStart
            };
            List <Vector3d> vecList = new List <Vector3d>()
            {
                crv.TangentAtStart
            };
            List <double> paramList = new List <double>()
            {
                0.0
            };
            bool tolBool    = false;
            bool endPtsBool = false;

            //warning message
            if (crv.PointAtStart.DistanceTo(crv.PointAtEnd) < distanceList.Max())
            {
                endPtsBool = true;
            }

            List <Curve> curves = new List <Curve>();

            curves.Sort((x, y) => x.PointAtStart.Z.CompareTo(y.PointAtStart.Z)); // Sort curve based on Height

            //recursion

            while (true)
            {
                //reset i if distance list end reached but curve is still long.
                if (i >= distanceList.Count - 1)
                {
                    switch (rep)
                    {
                    case 0:
                        i = -1;
                        break;

                    case 1:
                        i = distanceList.Count - 2;
                        break;

                    case 2:
                        goto Finish;
                    }
                }
                // increment
                i++;
                j++;

                //intersection properties for
                double       currentParam    = paramList[j];
                double       currentDistance = distanceList[i];
                NurbsSurface nurbsSrf        = new Sphere(crv.PointAt(currentParam), currentDistance).ToNurbsSurface();

                if (currentDistance < tol)  // if current distance is smaller than document tolerance, remove distance from computation
                {
                    tolBool = true;
                    distanceList.RemoveAt(i);
                }

                currentDistance = crv.Split(currentParam)[0].GetLength() + (distanceList[i] * 1.1);

                // sphere-curve intersection
                // using  overload with curve domain to limit intersection area- allows to break while-loop when curve reaches the end.
                CurveIntersections events = Intersection.CurveSurface(crv, new Interval(currentParam, currentDistance), nurbsSrf, tol, tol);

                if (events != null && events.Count > 0)
                {
                    if (events.Last().ParameterA > paramList.Last())
                    {
                        ptList.Add(events.Last().PointA);
                        vecList.Add(crv.TangentAt(events.Last().ParameterA));
                        paramList.Add(events.Last().ParameterA);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }

Finish:
            crvList.Add(crv);
            ptList.Add(crv.PointAtEnd);
            vecList.Add(crv.TangentAtEnd);
            paramList.Add(crv.Domain.Max);

            vd.Curves               = crvList;
            vd.Points               = ptList;
            vd.Tangents             = vecList;
            vd.Parameters           = paramList;
            vd.WarningMessageTol    = tolBool;
            vd.WarningMessageEndPts = endPtsBool;

            return(vd);
        }
        private SolveResults ComputeDivs(Curve crv, ConcurrentDictionary <int, List <double> > distanceList)
        {
            distanceList.Values[1]

            if (distanceList.Count == 0)
            {
                return(null);
            }

            if (crv.PointAtStart.DistanceTo(crv.PointAtEnd) < distanceList.Max())
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, " Distance between start and end points of curve(s) may be too small." +
                                  " If it yields undesirable results, consider increasing distance between them to max value in the supplied distances.");
            }

            // if parameter is within region A, use items from dictionary list A )
            //
            SolveResults result = new SolveResults();

            crv.Domain = new Interval(0, crv.GetLength());

            double t1 = crv.Domain.T1;
            double tol = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;
            int    i, j;

            i = j = -1;

            List <Curve>   crvList = new List <Curve>();
            List <Point3d> ptList  = new List <Point3d>()
            {
                crv.PointAtStart
            };
            List <double> paramList = new List <double>()
            {
                0.0
            };

            //List<double> div2 = distanceList2;


            // TODO: Fix intersection issues with curves that have their start and End points too close to each other; eg:closed curves.

            while (true)
            {
                //reset i if distance list end reached and curve still exists.
                if (i >= distanceList.Count - 1)
                {
                    i = -1;
                }

                // increment
                i++;
                j++;

                if (distanceList[i] < tol)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, " Distances less than or equal to rhino model tolerance will be ignored");
                    distanceList.RemoveAt(i);
                }

                // sphere-curve intersection
                // using  overload with curve domain to limit intersection area- allows to break while-loop when curve reaches the end.
                CurveIntersections events = Intersection.CurveSurface(crv, new Interval(paramList[j], t1), new Sphere(crv.PointAt(paramList[j]), distanceList[i]).ToNurbsSurface(), tol, tol);

                if (events != null && events.Count > 0)
                {
                    paramList.Add(events.Last().ParameterA);
                    ptList.Add(events.Last().PointA);
                }
                else
                {
                    break;
                }
            }

            crvList.Add(crv);
            ptList.Add(crv.PointAtEnd);
            paramList.Add(crv.Domain.Max);

            result.Curves     = crvList;
            result.Points     = ptList;
            result.Parameters = paramList;
            //result.div2 = div2;

            return(result);
        }