Jump to content

Select random point within a radius


smuseus

Recommended Posts

Hi,

I'm new to Houdini and I'm having some trouble getting VOP_SOP doing what i want.

I have a particle system with two groups. Now I want to for each particles in the first group find and random particle within an certain radius within the other group.

Now through a VOP_SOP I manage to find particles within a certain radius of a point. Whats keeping me stuck is that can't figure out how to select a random point of those point within this distance.

Any ideas?

Link to comment
Share on other sites

Uhm...tricky one. Not sure I got this right but here is my attempt.

The red group goes and finds a partner in the green group. The id attribute is in blue. The partner id of that particle is in pink. If the particle has no partner (green group) then the partner id is -1. Don't understand why sometimes red group is -1.

There's got to be an easier 2 node way...

Actually, this should be easier in Python. I'll knock you up something if I have time today.

groupme.hipnc

post-4013-12832218894_thumb.jpg

Edited by Macha
Link to comment
Share on other sites

err... maybe this does what you want by using a python script. I haven't fully checked it but it should basically work.

In case the python script doesn't travel along with the file, here it is. It writes to an an attribute called pairs, which contains the pair id.

from random import choice

geo = hou.pwd().geometry()
points = geo.points()
r = hou.pwd().evalParm("r") 
group1 = []
group2 = []


for p in points:
    if p.attribValue("attgroup") == 1:
        group1.append(p)
    else:
        group2.append(p)

for p1 in group1:
    l1 = []
    for p2 in group2:
        d = p1.position().distanceTo(p2.position())
        if d < r:
            l1.append(p2.attribValue("id"))
    if len(l1) > 0:
        brother = choice(l1)
        p1.setAttribValue("pairs",brother)

groupme.hipnc

post-4013-128323432754_thumb.jpg

Edited by Macha
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...