delete point within a threshhold

   1490   7   1
User Avatar
Member
143 posts
Joined: 7月 2015
Offline
Hello

I know this might sound strange but I have a problem with deleting points.
I have a straightforward code to delete a bunch of points based on the distance.
like if point number 5 finds 12, and 12 finds 5, both end up in the same group and then deleted.
I want only one of these pairs to be deleted,5 or 12 not both of them!
Oh God, I feel stupid.
Thank you

i@npts = nearpoints(0, @P, ch('dist'), 2);

foreach(int pnt;int p; @npts){
if (@ptnum != p && @group_deleEndPnts == 0){
v@pos = point(0, 'P', p);
f@lenX = length(@P.x -@pos.x);
f@lenZ = length(@P.z -@pos.z);
if (@lenX < ch('delX') && @lenZ < ch('delZ'))
setpointgroup(0, 'deleEndPnts', p, 1, 'set');

}
}
User Avatar
Member
900 posts
Joined: 2月 2016
Offline
nearpoints() function needs an array, you are just declaring a single int attribute with i@npts

Use
i[]@npts
Edited by Andr - 2022年12月23日 05:12:00
User Avatar
Member
143 posts
Joined: 7月 2015
Offline
yes, That was a typo I believe.
but still, I have the same problem.
the pairs are deleted not one of them!
User Avatar
Member
900 posts
Joined: 2月 2016
Offline
what if you try to be specific about the array data type also here ?

 foreach(int pnt;int p; i[]@npts)
Edited by Andr - 2022年12月23日 05:57:18
User Avatar
Member
143 posts
Joined: 7月 2015
Offline
well, I did that too but ...
here is the file please take a look.
Edited by MirHadi - 2022年12月23日 06:56:26

Attachments:
delete point threshhold.hip (117.1 KB)

User Avatar
Member
900 posts
Joined: 2月 2016
Offline
See if something like this helps: we proceed to the threshold operations only if @ptnum is lower than nearpt , so that we can act only on one point of the pairs.

int nearpts [] = nearpoints(0, @P, ch('dist'), 2);
removeindex(nearpts, 0); // remove self
float lenX, lenZ;
vector nearpos;
int nearpt = nearpts[0];
if ( @ptnum < nearpt )
    nearpos = point(0, 'P', nearpt);
    lenX = length(@P.x - nearpos.x);
    lenZ = length(@P.z - nearpos.z);
    if (lenX < ch('delX') && lenZ < ch('delZ'))
        i@group_deleEndPnts = 1;
Edited by Andr - 2022年12月23日 07:38:47
User Avatar
Member
143 posts
Joined: 7月 2015
Offline
neat, That's doing the trick.
thank you
User Avatar
Member
131 posts
Joined: 8月 2012
Offline
Is this method faster than using Fuse SOP?
  • Quick Links