# Inverse python function of CurveArcLengthPoint and other often-used constructs for which probably already whorter solutions exist

Dear community,

Just wondering if there is an inverse function of CurveArcLengthPoint
i.e., a function that gives the length of a curve between the curve start point and a given other point.

Currently, I use a small function like below, but my gut feeling says this already exists somewhere

``````GetCurveLengthFromStartToPoint( idCurve, ptPoint )
arrTemp = rs.CurveDomain( idCurve )
idTemp = rs.AddSubCrv( idCurve, arrTemp, rs.CurveClosestPoint( idCurve, ptPoint ) )
dblDistance = rs.CurveLength( idTemp )
rs.DeleteObject( idTemp )
return dblDistance
``````

Also, I very often use constructs of the form

`````` pt = rs.VectorAdd( pt0, rs.VectorScale( vecTemp, 100) )
``````

Or

``````idLine = rs.AddLine(  rs.VectorAdd( pt0, rs.VectorScale( vecTemp, -100) ),  rs.VectorAdd( pt0, rs.VectorScale( vecTemp, 100) )
``````

Can this be done more efficiently using existing methods or is my way of using these as help functions the right way?

Kind regards,

Filip

Hi Filip,

As for your curve length issue:
I do not think there is some method which will directly do that. And basically you did it right. The only thing that could be improved is using RhinoCommon methods directly instead of rhinoscriptsyntax functions. In this way you would not have to delete the sub curve:

``````def getCurveLengthFromStartToPoint(idCurve, ptPoint):
curveObj = rs.coercecurve(idCurve)
ptObj = rs.coerce3dpoint(ptPoint)
trimmedCrv = curveObj.Trim(curveObj.Domain, curveObj.ClosestPoint(ptObj, 0.0))
return trimmedCrv.GetLength()
``````

If I understood you correctly one the vector issue, you want to add two vectors, but the second one should be scaled?
You can sum and multiply the Vector3d type:

``````pt = rs.coerce3dvector(pt0) + rs.coerce3dvector(vecTemp)*100
``````
1 Like

Hi Filip,

You can feed a subdomain into rs.CurveLength to specify a segment of the curve:

``````import rhinoscriptsyntax as rs

Curveid=rs.GetObject("Select Curve",4)
point=rs.GetPointOnCurve(Curveid,"Select Point on curve")
PointParam=rs.CurveClosestPoint(Curveid,point)

Length=rs.CurveLength(Curveid,-1,(0,PointParam)) #0 is start parameter of the curve!
print Length
``````

With RhinoCommon you can use GetLength on a curve sub domain
http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_Geometry_Curve_GetLength_1.htm
http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_Geometry_Curve_GetLength_3.htm