Polyline Evaluate Length in rhino3dm

Hi,

Does rhino3dm have a method similar to Evaluate Length or Divide Length for a Polyline curve?

Or I need to work it out from the length of each segments?
(see Is the domain of a polyline linear? - #5 by AndersDeleuran)

I am writing a Naviswork addin and I have a Rhino licence but I don’t know if the person who is going to use it will have Rhino installed.

Thank you
Giovanni

Hi @Giovanni1,

Give a Polyline, you should be able to calculate it’s length using Polyline.Length. A polyline is just an array of points, to the calculation is pretty simiple.

– Dale

Thank you Dale.

Sorry I wasn’t clear. I am trying to find a point at a certain distance along the polyline (i.e. 35m from the start). I thought Evaluate Length would be the easiest way but I cannot find that method in rhino3dm.

Thank you

Hi @Giovanni1,

You should be able to do that with some simple vector math.

// Some arbitrary line
var point0 = new Point3d(15.660128434922481, 65.84636006795553, 0.0);
var point1 = new Point3d(66.036967855848303, 5.3510956351343566, 0.0);
var line0 = new Line(point0, point1);
var length0 = line0.Length;

// Direction vector
var direction = point1 - point0;
direction.Unitize();
direction *= 35.0; // Your distance

var point2 = point0 + direction; // Create by offsetting point0
var line1 = new Line(point0, point2);
var length1 = line1.Length;

Does this help?

– Dale

I wrote this one for my need (Nautilus Plugin). If you want to begin at start put 0 at parameterOnCurve,

        public static double WalkPositiveOnPolylineParameter(Polyline polyline, double parameterOnCurve, double arg_distance)
        {
            double distance = Math.Abs(arg_distance);
            distance = distance % polyline.Length;

            Point3d closestPointOnPolyline = polyline.PointAt(parameterOnCurve);
            double output = parameterOnCurve;
            Point3d lastPoint = closestPointOnPolyline;

            double lengthWalkedOnPolyline = 0.0;
            double lastParameter = parameterOnCurve;


            for (int i = (int)Math.Floor(parameterOnCurve) + 1; i < polyline.Count; i++)
            {
                double newStepDistance = polyline[i].DistanceTo(lastPoint);

                if ((distance - lengthWalkedOnPolyline) <= newStepDistance)
                {
                    double param = ((double)(i % polyline.Count) - lastParameter) * (distance - lengthWalkedOnPolyline) / newStepDistance;
                    lengthWalkedOnPolyline = distance;
                    output = lastParameter + param;
                    break;
                }
                else
                {
                    lengthWalkedOnPolyline = lengthWalkedOnPolyline + newStepDistance;
                    lastPoint = polyline[(i)];
                    lastParameter = (double)i;
                }
            }
            if (lengthWalkedOnPolyline < distance)
            {
                output = WalkPositiveOnPolylineParameter(polyline, 0.0, distance - lengthWalkedOnPolyline);
            }
            return output;
        }
3 Likes

Thank you very much Dale and Laurent.

Dale, Yes that helps. Laurent has provided the solution I was looking for.

Cheers
Giovanni