Picking a random point for a group

   3617   1   1
User Avatar
Member
18 posts
Joined: Jan. 2020
Offline
Hi,

I have this simple problem that I just cant figure out. So I want to pick a single random point from a group I have previously created (lets say group1). I do this using a group by range with random start (rand($F) * npoints(0) and length = 1 (as image below). But it doesnt work since the start value sometimes pick a number not in the group (even after I put the base group as group1).

Is there a better way to pick random points from a group?

Additionally, I can't figure out how to pick a group based on a previous group (the intersection of both group). Is there a way to do this?

Edit: sketch added. So I am able to group a set of points (named g1), and from that point, I want to pick 1 random point (and create a subgroup probably named it g2). Later, I want to copy box at g1 and sphere at g2. It's simple but I cant figure out how. Any help?

Thanks
Edited by jttarigan - Oct. 7, 2021 14:23:13

Attachments:
subgroup skecth.png (30.7 KB)

User Avatar
Member
406 posts
Joined: April 2017
Offline
Given a group of random points, you could use the Group Range SOP to select a random point using the first group as the base group parameter.

Group Range doesn't have a built-in random selector but you could set the Range Type to "Start and Length", leave the length at 1, and pick a random starting point from your previous group:

rand(2)*npointsgroup(0, group1)

where (2) is your random seed. You could change that to any number or channel reference.

To copy different geometry to different groups, you could either run successive Copy to Points operations using group masks for the template points, or you could convert your groups to a name attribute via the Name SOP, and then use that name attribute as your Piece Attribute on a single Copy to Points.

Attaching an example.

Attachments:
copy_to_rand_groups_toadstorm.hip (158.1 KB)

MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
  • Quick Links