How to divide the curve by the varying distance?

Hello everyone.
I wanted to divide the curve into ino straight lines with varying straight lines. (First curve with red lines)
I want to have lenght of the lines as the input. The only solution I have found is considering the length of the curve (second curve with the orange lines) which is not the same with the legth of lines if I connect the endpoints.

I would really appreciate if you could help me. Thanks in advance

here is photo what i mean

I want to have lenght of the lines as the input

What do you mean by this?

In the Divide Distance
image
you can divide the cuve by specified distance. But it takes only one input/number. I want ro devide the curve lets say by 2, 3, 4 i.e, varying magnitude of lenght.

If you want something like that, you can’t fix the last distance

This solution is acceptable. Could I have the python component you used? Thank you very much.

Not sure if this is what you’re after. You probably want more control over line lenghts.


line.gh (15.9 KB)

curve multi_distances.gh (10.3 KB)

1 Like

Thank you all for your answers. However I think I was not clear with my question. Let me explain again, because I could not resolve the proble still.


As you see in the drawing, I want my curve to be discretized with variying distance, in this case they are noted as r. If you select in grasshopper Divide Distance it does the same but only with constant r. I want to make it as an input of series of r.
Thank you all for your kind replies.

hello @Sardor_N, what is not good with @anon39580149 answer ? It seems to be exactly what you asked !!!

Nautilus plugin as something near this but not exactly.

1 Like

Yes, I was also thinking @anon39580149 solution was suitable. But I could not use it for the curve i have.


I am not sure what is the problem. It does not react even if I change the slider numbers.

I think you are experiencing common problem of people that don’t provide enough information on their problems. Details matter as the tools has its limitation. I am not sure as you provide quite nothing but it seems your curve has a big length (100 000 units) compared to what @anon39580149 use as tolerance in the code (0.001). Change the tolerance to 1 and see if it is better. For me it worked.
There are many problem that are just scale related.

It is not working in my case. I would be happy if you could point on other possible mistakes. I am still learning :smiley:

Post your curve !! Internalize the data. We are all learning, I learned a lot by answering questions.
image

here you go :eyes:
curve.gh (14.9 KB)

The script for 2d curve only, your curve is not planar

1 Like

Your curve is not planar it does not work with @anon39580149 tool. I have not this problem with my tool has I don’t rely to Curve Intersection.
There is a deviation of 100 units.
The only workaround for now is to project your curve on a plane.


curveLD.gh (19.5 KB)

Another example of Details Matter

2 Likes

Late to the party, I have a Divide Distance Multiple component.

magicteddy.gha (78 KB)

protected override void SolveInstance(IGH_DataAccess DA)
        {
            Curve curve = null;
            bool wrap = true;
            List<double> distances = new List<double>();

            if (!DA.GetData(0, ref curve))
            {
                return;
            }

            if (!DA.GetDataList(1, distances))
            {
                return;
            }
            if (!DA.GetData(2, ref wrap))
            {
                return;
            }

            if (curve==null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Null Curve.");
                return;
            }
            if (distances.Count==0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "At least one distance is required.");
                return;
            }
            if (curve.GetLength() < distances[0])
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Curve total length is smaller than the first distance.");
            }

            
            Point3d currPt = curve.PointAtStart;

            List<Point3d> pts = new List<Point3d>() { currPt };
            List<double> dividedParams = new List<double>() { curve.Domain.T0 };
            List<Vector3d> tangents = new List<Vector3d>() { curve.TangentAtStart };

            Curve c = curve.DuplicateCurve();            
  
            int i = 0;
            double tol = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;

            while (i < distances.Count)
            {
                double r = distances[i];
                Sphere s = new Sphere(currPt, r);

                if (Rhino.Geometry.Intersect.Intersection.CurveBrep(c, s.ToBrep(), tol, out Curve[] cc, out Point3d[] pc, out double[] t))
                {
                    if (t.Length > 0)
                    {
                        Array.Sort(t, pc);
                        currPt = pc[0];
                        pts.Add(currPt);
                        dividedParams.Add(t[0]);
                        tangents.Add(c.TangentAt(t[0]));

                        c = c.Trim(t[0], c.Domain.T1);

                        if (wrap)
                        {
                            distances.Add(distances[i]);
                        }

                        i++;
                    }
                    else
                    {
                        //no more tries
                        break;
                    }

                }
                else
                {
                    //no more tries
                    break;
                }


            }
            
            DA.SetDataList(0, pts);
            DA.SetDataList(1, tangents);
            DA.SetDataList(2, dividedParams);

        }
10 Likes

Thank you very much. It seems to be working. I will check it at work tmrw to be 100%sure. :smiley: :+1:

Thank you very much @magicteddy. The component is working well :muscle:

1 Like

Hi, is there a chance you could make that script that puts more points even if there are fewer numbers applied?
curve multi_distances.gh (10.8 KB)

Cheers,