Vex question: two highest (@P.y) points from a group?

   280   2   0
User Avatar
Member
280 posts
Joined: 8月 2018
Online
I have four points in a point group - "endPts". I want to find the two highest (@P.y) points.

So, I thought:
In a detail wrangle, create an array and run through all the points. Check if the point is in the "edgePts" group, if so, append it's P.y value it to an "endPtsArray" array. Sort the array. The last two array values will be from the highest two points.

Here's my vex. Where am I going wrong?

float endPtsArray[];
for(int i=0; i<@numpt; i++)
{
    if (inpointgroup(0, "endPts", i)==1)
    {
        append(endPtsArray, @P.y);
    }
}
endPtsArray = sort (endPtsArray);
Edited by Mike_A - 2024年12月11日 16:43:11
User Avatar
Member
318 posts
Joined: 1月 2013
Offline
An easy way to do this:
upadate:
float pos[];
int grp[] = expandpointgroup(0, "endPts");
foreach(int pt; grp){
    push(pos, vector(point(0, "P", pt)).y);
}

float result[] = sort(pos);
int pts[] = argsort(pos)[-2:];
Edited by alexwheezy - 2024年12月11日 17:21:09
User Avatar
Member
280 posts
Joined: 8月 2018
Online
Alex - many thanks, that looks great, I'll be trying it out very soon : )
'expandpointgroup' is a new one to me.
I appreciate your expertise and generosity!
Edited by Mike_A - 2024年12月13日 09:24:13
  • Quick Links