Jump to content

grouping 1 random point


isah_voodoo

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. 

Link to comment
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.

Link to comment
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 !
 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...