VEX: Point wrangle question...

   2919   4   1
User Avatar
Member
402 posts
Joined: Aug. 2015
Online
Hello;

I scattered 2 points on a grid, and I would like to delete some points on it, which are near to scattered point's position.

The problem is , when I try to remove them, it deletes points near to {0,0,0} position, too !
I can't figure out what the problem is…!

Here I attached a snapshot from my scene:
Edited by Masoud - Sept. 16, 2018 11:52:49

Attachments:
VEX Test_01.hip (76.4 KB)
Capture.JPG (189.4 KB)

Masoud Saadatmand (MSDVFX)
User Avatar
Member
8506 posts
Joined: July 2007
Offline
it's because you have only 2 points in second input and you are iterating over first input with more than 2 points
so then this
vector BasePoint = point(1,“P”, @ptnum);
will return {0,0,0} for @ptnum above 1 as second input only has 0 and 1

you should think about the whole problem from the point of view of the points you are iterating about
lookup your scattered points from each grid point's location
and if it finds a point within given maxdist, delete the current grid point that is being iterated (@ptnum)
here is the full code to replace yours:

int pt = nearpoint(1, @P, chf("MaxDist"));
if (pt != -1) removepoint(0, @ptnum, 1);
Edited by tamte - Sept. 16, 2018 12:19:38
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
402 posts
Joined: Aug. 2015
Online
Thank you tamte;

According to your tips: to limit the iteration to number of points that I need, I changed my codes to :

vector BasePoint = point(1,"P", @ptnum);
int NearPts[] = nearpoints(0, BasePoint, chf("MaxDist"));

foreach(int inx ; NearPts)
{
    if(@ptnum<npoints(1))removepoint(0, inx);
}

And problem solved. But what is difference between nearpoint() and nearpoints() functions?
Edited by Masoud - Sept. 17, 2018 04:24:18
Masoud Saadatmand (MSDVFX)
User Avatar
Member
8506 posts
Joined: July 2007
Offline
well, no
according to my tips you'd use the code I posted
your approach still unnecessarily loops over stuff
and if you have just 1 point in your first input (or generally less than in second), it will not check against all points in second so it may miss the closest

nearpoint() just returns one closest point within radius or -1 if no such point found, which is all you need if you are checking from each grid point if there is any second input point within certain radius

nearpoints() in this form returns array of all points within radius
Edited by tamte - Sept. 17, 2018 09:47:49
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
402 posts
Joined: Aug. 2015
Online
Thank you tamte, you're right. I used your codes.
Masoud Saadatmand (MSDVFX)
  • Quick Links