Jump to content
Sign in to follow this  
isah_voodoo

grouping 1 random point

Recommended Posts

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. 

Share this post


Link to post
Share on other sites
i@group_single_point = floor(rand(chf('seed'))*@numelem) == @elemnum;

Something like this should work

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

@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.

Share this post


Link to post
Share on other sites

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 !
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×