Jump to content
Sign in to follow this  

Distance between points on a line

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

Share this post

Link to post
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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this