Jump to content

Resample Lines by length

Recommended Posts


I have some lines, and I want to add points to each line based on the length of the line. The longer the line, the fewer points I want to add , and the shorter the line , the more points I want to add. 
I have already calculated the perimeter of each line and stored the values in an attribute called " perm". 

After I isolated one line inside the foreach, I add the Resample node. I want to get the resample "length" parameter and divide it by the attribute "perm" to see what happens.

I have a point expression in the "Length" paramter of the resample to reference in the values of the perm attribute but it's not working...
point(opinputpath(“.”,0), $Ptnum, “perm”,0)

Is there something here I'm missing? I attached my file If anyone wants to take a look.


Thank you.


Share this post

Link to post
Share on other sites

hm maybe this is not what you looking for because its not proportional to the segment length but you can use the ptdist to delete if the points are x units apart from each other? And ctrl the the resample size with the segments count...I attached the file. 




Edited by jon3de

Share this post

Link to post
Share on other sites

After calculating their length, you can use a primwrangle on the lines.

// user parameters
float cut    = chf('cut');
float change = chf('restlength');

// identify point positions
int vtx_0 = primvertex(0, @primnum, 0);
int vtx_1 = primvertex(0, @primnum, 1);
int pt_0 = vertexpoint(0, vtx_0);
int pt_1 = vertexpoint(0, vtx_1);
vector pos_0 = point(0, "P", pt_0);
vector pos_1 = point(0, "P", pt_1);

// define slices based on user parameters
@restlength = pow(@restlength, change);
int slice = int( ceil(cut / @restlength) );
slice = max(slice, 2);

// add new primitive with points and vertices
int add_prim = addprim(0, "polyline");

for(int i = 0; i < slice; i++) {
    float mix  = i / float(slice - 1); 
    vector pos = lerp(pos_0, pos_1, mix);
    int add_pt = addpoint(0, pos);
    addvertex(0, add_prim, add_pt);

// remove the old primitives
removeprim(0, @primnum, 1);



  • Like 1

Share this post

Link to post
Share on other sites

with H16 what you can do is just rename your "perm" attribute to "segment_length" (or "num_segments" alternatively) and enable overriding attributes (should be enabled by default I think)

  • Like 1

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