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

   284   2   0
User Avatar
Member
280 posts
Joined: Aug. 2018
Offline
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 - Dec. 11, 2024 16:43:11
User Avatar
Member
318 posts
Joined: Jan. 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 - Dec. 11, 2024 17:21:09
User Avatar
Member
280 posts
Joined: Aug. 2018
Offline
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 - Dec. 13, 2024 09:24:13
  • Quick Links