find order from smallest to biggest value

   1332   7   0
User Avatar
Member
1010 posts
Joined: April 2017
Offline
Hi!

If I have 3 points with @myValue:
pt0: 1.5
pt1: -12.89
pt2: 561.8

… and I want to find the order from smallest to biggest value and set that in attribute i@myOrder so it gives me:

pt0 @myOrder = 2
pt1 @myOrder = 1
pt2 @myOrder = 3

I could do it with a bunch of IF statements but I'm sure there's an easier way. Any idea?

-Olivier
User Avatar
Member
1010 posts
Joined: April 2017
Offline
…Actually, I over-simplified my example.

My situation is this. I have a triangle and I managed to find the angle at each point and placed those values in @aglA, @aglB, @aglC. From there, I need to find smallest to biggest value and end up with:

pt0 @myOrder = 2
pt1 @myOrder = 1
pt2 @myOrder = 3

…since each value is stored on ALL points, I don't know how to proceed…

-Olivier

Attachments:
order_values.JPG (25.5 KB)

User Avatar
Member
2042 posts
Joined: Sept. 2015
Offline
You could store the point values in an array of floats, then use the sort function which will change the order of the points from least to greatest value.
User Avatar
Member
1010 posts
Joined: April 2017
Offline
I know how to read a point attribute value (point function), but I would like to do the opposite and write a value on a specific point attribute.
User Avatar
Member
1010 posts
Joined: April 2017
Offline
I just saw your post after I replied.

The sort function is interesting but I don't get how to go from a sorted array to figuring what point number has the smallest value… I'm lost!
User Avatar
Member
1010 posts
Joined: April 2017
Offline
AH!

Found it!


// 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”);
Edited by olivierth - Sept. 26, 2018 14:24:49

Attachments:
order_values_setpointattrib.JPG (20.4 KB)

User Avatar
Member
2042 posts
Joined: Sept. 2015
Offline
Saw you posted while I was responding…ignoring your last post as you seem to have found a way to do what you want, but to answer your question about sort in the context you gave earlier, thought you might want to look at this.
Edited by BabaJ - Sept. 26, 2018 14:41:12

Attachments:
Sort.hiplc (46.6 KB)

User Avatar
Member
1010 posts
Joined: April 2017
Offline
Ah!
Array_For_Sort [ @ptnum ]

that's a nice trick!

Thanks!

-Olivier
Edited by olivierth - Sept. 26, 2018 19:27:15
  • Quick Links