Jump to content

Resample Lines by length


logix1390

Recommended Posts

Hello,

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.

resample_by_length_Polylines.hip

Link to comment
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. 

resample_by_length_Polylines.hip

 

resample_by_length.jpg

Edited by jon3de
Link to comment
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);

 

counter_resample.hipnc

  • Like 1
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...