change @ptnum assignment in specific order

   2687   2   0
User Avatar
Member
1010 posts
Joined: April 2017
Offline
Hi!

I have 2 almost identical triangles (each from a different node) and I need the @ptnum to be consistent.

I would always want to have the point that has the smallest angle to be point 0. …and to always have the next point on the longest edge to be point 1 and the last one be point 2.

I'll be good with figuring the angles and the edge lengths. I just don't get how to change @ptnum from there…

Any ideas on this?

-Olivier
Edited by olivierth - Sept. 26, 2018 12:31:49

Attachments:
triangle_ptnum_change.jpg (56.4 KB)

User Avatar
Member
1010 posts
Joined: April 2017
Offline
Ah!

I think I know how. In the sort sop I can set it "by attribute". I'll experiment and come back if I managed to get it working.

-Olivier
User Avatar
Member
1010 posts
Joined: April 2017
Offline
Ah! found it!

I ended up just ordering the point number from smallest angle to biggest angle. (finding longest edge was useless)

// find Positions
vector p0 = point(0, “P”, 0);
vector p1 = point(0, “P”, 1);
vector p2 = point(0, “P”, 2);


// find edge lengths
float ab = distance(p0, p1);
float bc = distance(p1, p2);
float ca = distance(p2, p0);

// find vectors to next points
vector vab = normalize(p1 - p0);
vector vbc = normalize(p2 - p1);
vector vca = normalize(p0 - p2);
// find vectors to previous points
vector vac = normalize(p2 - p0);
vector vba = normalize(p0 - p1);
vector vcb = normalize(p1 - p2);

// find angles using each vectors
float aglA = acos(dot(vab, vac));
float aglB = acos(dot(vba, vbc));
float aglC = acos(dot(vca, vcb));

// set point value from angle A, B, C
f@angle = 0;
setpointattrib(0, “angle”, 0, aglA, “set”);
setpointattrib(0, “angle”, 1, aglB, “set”);
setpointattrib(0, “angle”, 2, aglC, “set”);


From there, I use a sort SOP and use the by attribute and use @angle.
Edited by olivierth - Sept. 26, 2018 14:49:49

Attachments:
sort_by_angle_value.JPG (136.7 KB)

  • Quick Links