danhprt Posted September 30, 2019 Share Posted September 30, 2019 (edited) 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 September 30, 2019 by danhprt Quote Link to comment Share on other sites More sharing options...
StepbyStepVFX Posted September 30, 2019 Share Posted September 30, 2019 (edited) 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 September 30, 2019 by StepbyStepVFX Quote Link to comment Share on other sites More sharing options...
danhprt Posted September 30, 2019 Author Share Posted September 30, 2019 Thanks! Thats exactly what I needed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.