Jump to content
Farmfield

Select specific numbers of points based on height

Recommended Posts

This just gotta have a simple solution, just couldn't think of a straightforward way to solve it. I'm looking for a division independent way to group N amount of random points from the bottom (P.y == 0) and an equal amount of random points from the rest (@P.y > 0). And sure, you can solve this several ways, using a couple of SOPs, but I'm looking for something like a single expression in a group- or wrangle SOP, if that's even possible. 

The only one-node-solution I can think of is splitting the bottom and other points into arrays in a wrangle SOP and choose N amount of points from each - but I instinctively feel there's gotta be a really simple solution I'm missing, it's my default mode, missing the obvious... :D

grid.hiplc

Share this post


Link to post
Share on other sites

It's easy, if you use HOM instead of Expression:

import random

n = 100

bottom = []
rest = []
for p in hou.pwd().inputs()[0].geometry().points():
    if abs(p.position()[1]) < 1e-6:
        bottom.append(p.number())
    else:
        rest.append(p.number())

random.seed(12345)
random.shuffle(bottom)
random.shuffle(rest)

return ' '.join(map(str, bottom[:n] + rest[:n]))

Result:

complex_pattern.png

 

complex_pattern.hipnc

Share this post


Link to post
Share on other sites

Aah, I explained this badly, I want two groups, one with N number random points at Y = 0 and one with N random points out of the remaining points.

And I really gotta do a Python refresher, haven't gotten into HOM at all.

Share this post


Link to post
Share on other sites

It's mostly the same, you need to add unselected points to the rest list before sorting it randomly:

import random

n = 100

bottom = []
rest = []
for p in hou.pwd().inputs()[0].geometry().points():
    if abs(p.position()[1]) < 1e-6:
        bottom.append(p.number())
    else:
        rest.append(p.number())

random.seed(12345)
random.shuffle(bottom)

rest += bottom[n:]
random.shuffle(rest)

return ' '.join(map(str, bottom[:n] + rest[:n]))

 

  • Like 1

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

×