isah_voodoo Posted November 11, 2018 Share Posted November 11, 2018 Hello I am trying to group only 1 random point on a grid and change it based on a seed..... I know how to group many random points... like this : rand(@elemnum) < 0.3 but how can I randomly group only ONE point randomly ? I tried something like this: rint(rand(@ptnum)<0.001) It works i think but this is not a very robust way of doing things....any suggestions ? please help , thank you. Quote Link to comment Share on other sites More sharing options...
jkunz07 Posted November 11, 2018 Share Posted November 11, 2018 i@group_single_point = floor(rand(chf('seed'))*@numelem) == @elemnum; Something like this should work 1 1 Quote Link to comment Share on other sites More sharing options...
isah_voodoo Posted November 11, 2018 Author Share Posted November 11, 2018 Thank you jkunz this works perfectly...Not entirely sure I know what is going on in the code though haha... What exactly is @numelem ? Cheers Quote Link to comment Share on other sites More sharing options...
jkunz07 Posted November 12, 2018 Share Posted November 12, 2018 @numelem is the total number of elements being processed. Depending on the what the wrangle is set to operate on (points, vertices, prims, or detail). You could use npoints() or nprimitives() vex functions instead if you want. The code is generating a random number between 0 and 1. This is then scaled to fit the number of points (multiplying by @numelem). floor() function eliminates anything after the decimal, so we have a whole number. Then we check if it matches the current element number (@elemnum). If it matches, this will evaluate to 1, adding it to the group, the rest of the points that don't match will evaluate to 0 and not be included in the group. Is that clear? Let me know if you have any more questions. Quote Link to comment Share on other sites More sharing options...
isah_voodoo Posted November 12, 2018 Author Share Posted November 12, 2018 Hi jkunz, I think i get it now. this is a really great method... I tried to replace elemnum and numelemwith npoints and ptnum but it doesn't seem to work . So i did this: i@group_single_point = floor(rand(chf('seed'))*@npoints) == @ptnum; wouldn't this be doing the same thing ? Thank you for you help ! Quote Link to comment Share on other sites More sharing options...
jkunz07 Posted November 13, 2018 Share Posted November 13, 2018 The variable for total number of points is @numpt. There is a function npoints() which is different for a variable. npoints(0) (the zero specifies the input geometry) will return the same result as @numpt. This part of the docs might be worth looking at: http://www.sidefx.com/docs/houdini/vex/snippets.html#indexing Quote Link to comment Share on other sites More sharing options...
isah_voodoo Posted November 14, 2018 Author Share Posted November 14, 2018 Makes sense. thanks for the help jkunz Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.