Jump to content

Select specific numbers of points based on height


Farmfield

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

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

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