Jump to content

Distance between points on a line


danhprt

Recommended Posts

I'm currently trying to calculate distance between points along a line, I'm sure this is simple but I cant quite figure out how to do this.

If I have two points, 0 and 1 I know that you can use this vex function to get the distance between them:

vector p1 = point(0,'P',0);
vector p2 = point(0,'P',1);

@distance = distance(p1,p2);

What I'm trying to figure out is how can I use this to get the distance between each point on a line of say 50 points. Is there a way I can iterate this function along all the points? Any other solutions welcome of course!

Edited by danhprt
Link to comment
Share on other sites

If you don't need to have one single primitive, use a Convertline SOP (it transforms 1 line primitive containing multiple points into as many primitives as you have segments), and then use a Measure SOP on Perimeter, and you'll have the distance between two points as a "restlength" attribute on each primitive.

Otherwise, if you have 1 line primitive with N points and N-1 segments (that are ordered correctly : otherwise use a Sort SOP node), you will have to store the length on the first (or second) point of each segment (as a point attribute therefore...). You can do it with a Point Wrangle with the folllowing code :

vector nextPt = point(0,"P",@ptnum+1);

f@distance = distance(@P, nextPt);

Problem is, you have more points than segments, so careful on how to use that attribute afterward... If you tell us why you need that, we may give you more interesting answers :-)

Edited by StepbyStepVFX
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...