New curve division component

Hi there! I made a new component which could be handy for some.

It offers a new way of dividing a curve. It works similar to “Divide Distance”, but instead of distributing points evenly, it allows to separably specify distance between every two points.

It is my first grasshopper component. It is effect of a free evening when I wanted to take my thoughts away from my master thesis. Coding is pure pleasure for me

ArchiCoder001.gha (10 KB)

Hope it will be usefully for some, especially those who don’t know know to code yet. I tried to make it as robust as possible. A bit of feedback will be welcome :slight_smile: . Later, I will probably upload the source code.

3 Likes

Hi again,
I am adding here my code for the Divide Unequally component, so that it is not only on my hard drive. :slight_smile:

Since i just went through Daniel’s Shiffman tutorials on how to use git, my VS solution and the “plug-in” (with one small bug corrected) can be found here: https://github.com/archi-coder/GHC_CurveDivideUnequally

public static void DivideUneqully(this NurbsCurve curve, List<double> distances, bool delete, out List<double> intersectionParameters, out List<Point3d> points, out bool[] pattern)
        {
            int segments = distances.Count;
            points = new List<Point3d> { curve.PointAtStart }; // list to store the division points
            intersectionParameters = new List<double>{curve.Domain.T0}; // list to store the t parameters of division points
            pattern = new bool[segments]; // list to store booleans, True if divison point was created
            for (int i = 0; i < segments; i++) pattern[i] = false;

            int counter = 0;

            for (int i = 0; i < segments; i++)
            {
                if (distances[i] <= 0) continue; // skips when distance is not bigger then zero

                // Checks the intersections of a curve with a sphere which radius is the given distance
                Brep sphere = (new Sphere(points[counter], distances[i])).ToBrep();
                bool succsess = Rhino.Geometry.Intersect.Intersection.CurveBrep(curve, sphere, 0.01, 0.01, out double[] tempParameters);
                if (!succsess) break;

                // Chooses the first intersection point on the curve
                Array.Sort(tempParameters);
                double previous = intersectionParameters[counter];
                double next = curve.Domain.T1;
                foreach (double t in tempParameters) if (t >= previous) { next = t; break; }

                Point3d intersectionPoint = curve.PointAt(next);

                if  (next == previous ||
                    (next == curve.Domain.T1 &&
                    delete == true &&
                    distances[i] != points[counter].DistanceTo(intersectionPoint)))
                    break;
                
                // Stores the divison point and its t parameter 
                intersectionParameters.Add(next);
                points.Add(intersectionPoint);
                pattern[i] = true;

                counter++;

            }
        }

I am still just staring to learn coding, so if anybody sees space for improvement please let me know. It is important to learn good habits already on the beginning :wink: