Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Curve Length

public_publicpublic_public Member Posts: 5
Please suggest a method to measure the distance along a curve between specified points.
Thank you

Comments

  • MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,050 ✭✭✭✭✭
    @public_public
    Could you show an example
    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • public_publicpublic_public Member Posts: 5
    FeatureScript 920;<br>import(path : "onshape/std/geometry.fs", version : "920.0");<br><br>annotation { "Feature Type Name" : "CurveLength" }<br>export const CurveLength = defineFeature(function(context is Context, id is Id, definition is map)<br>    precondition<br>    {<br>        annotation { "Name" : "Point_1", "Filter" : EntityType.VERTEX, "MaxNumberOfPicks" : 1 }<br>        definition.Point_1 is Query;<br><br>        annotation { "Name" : "Point_2", "Filter" : EntityType.VERTEX, "MaxNumberOfPicks" : 1 }<br>        definition.Point_2 is Query;<br><br>    }<br>    {<br>        var myStartPoint is Vector = evVertexPoint(context, {<br>                "vertex" : qNthElement(definition.Point_1, 0)<br>            });<br><br>        var myEndPoint is Vector = evVertexPoint(context, {<br>                "vertex" : qNthElement(definition.Point_2, 0)<br>            });<br>        var myCurveF is Query = qContainsPoint(qEverything(EntityType.EDGE), myStartPoint);<br>        var myCurve is Query = qContainsPoint(myCurveF, myEndPoint);<br>        var Length_1 is ValueWithUnits = evLength(context, {<br>                "entities" : myCurve<br>            });<br><br>        debug(context, Length_1);<br><br>    });<br><br>

    "evLength" only evaluates total length. But I need calculate the length between any points on the curve.





  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,681
    I’d be interested in a solution to this. All I can think of is to:
    1. Iterate over the curve to find the parameter closest to each point using evEdgeTangentLine
    2. Compare parameters against overall curve length 

    Senior Director, Technical Services, EMEAI
  • public_publicpublic_public Member Posts: 5
    Currently I'm using the same approach. But looks like it is a little bit slow. evLength works faster. I iterate over 10 000 points to get necessary tolerance. It is nice to get the reverse function to evEdgeTangentLine.

  • owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
    edited October 2018
    Could you project it onto a new temp sketch, split it, measure it, delete the sketch?  No iterations that way.  Edit - Dumb Idea

    Owen S.
    Business Systems and Configuration Controller
    HWM-Water Ltd
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,681
    @owen_sparks I’m guessing it may not be a 2D curve

    @public_public I will post a faster solution soon
    Senior Director, Technical Services, EMEAI
  • public_publicpublic_public Member Posts: 5
    It looks like a 3D curve can not be split for some reason. The curve's split issue already arose here

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,681
    @public_public - a little more involved than I first thought, but fast and accurate 



    https://cad.onshape.com/documents/d103e50535cbfbf38dd6e51b


    Senior Director, Technical Services, EMEAI
  • public_publicpublic_public Member Posts: 5
    Thanks for your support!
  • Eleanor_CoffinEleanor_Coffin Member Posts: 43 ✭✭
    edited February 2022
    @NeilCooke or anyone who knows enough about FeatureScripts -- (I'm learning but I'm not that familiar yet!), if you had a chance would you be able to make it so that FS saves the curve length value in a new variable?

    Basically I'm modeling a drive belt with two different-sized pulleys, so I want to measure the exact length of the belt and then save use that length in the part number -- so if anyone knows of a different way to do that, I'd be open to that too. Thank you!

    Posted too soon, just found a FS that does exactly what I'm asking:
    https://cad.onshape.com/documents/d8a36f7517523544158ae686/w/b257afccef639b5ffa33e3fe/e/a2254749aecfdeb3b2c601c5
  • tedmtedm Member Posts: 2
    NeilCooke said:
    @public_public - a little more involved than I first thought, but fast and accurate 

    https://cad.onshape.com/documents/d103e50535cbfbf38dd6e51b


    @NeilCooke -- your script works great when measuring between two points that fall within a curve. In selecting the end points of a curve, the script returns an error.  Please see pic below.  Purely informative, although I wouldn't cry if you made a fix : )  Thank you,
    Ted



  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,681
    @ted_m_ you can use a measured variable if it's just the length of the full curve that you need. That script (which is very old) also creates the curve between the two points. 
    Senior Director, Technical Services, EMEAI
Sign In or Register to comment.