Grasshopper

algorithmic modeling for Rhino

Hello,

I have a large 3D grid of points an would like to "slice" it with a plane surface that I have drawn in Rhino, i.e. delete all points that are "below" the surface.

I have succeeded using the attached parallel script, but it is still too slow in my case. I need to be able to move the reference surface around in Rhino and get as quick a feedback in GH as possible.

def closestpt(point):
    pattern = []

    rc, u, v = srf.ClosestPoint(point)
    surface_xyz = srf.PointAt(u,v)
    dirPos = rs.PointAdd(surface_xyz, surface_normal)
    dirNeg = rs.PointSubtract(surface_xyz, surface_normal)
    dist = rs.Distance(surface_xyz, point)
    if (rs.Distance(point, dirPos) > rs.Distance(point, dirNeg)): bool = False
    else: bool = True
    pattern.append(bool)

    return pattern

surface_normal = rs.SurfaceNormal(srf, (0,0))
pattern = ghpythonlib.parallel.run(closestpt, pts, True)

Any ideas?

Cheers,

Max

Views: 2286

Attachments:

Replies to This Discussion

If instead of a surface you use a plane, you can use the .ValueAt(pt) method, if it is less than zero then cull the point.

In one line: pattern = Pln.ValueAt(pt) > 0

Much better, thanks!

Hi Max, I couldn't get your file to run (missing internalized geo and I think it might be written in Rhino 6 WIP, maybe?). Anywho, a couple of observations:

1) The method itself will likely run faster using some simple vector math and RhinoCommon (basically, to check if a point is above a plane: Calculate the dotproduct between the plane Z-Axis and a vector from the plane origin to the point. If this is negative you're below, else above the plane).

2) The cost of inputting/outputting large lists of objects can be very expensive (see this thread for tips). Best way to get around this is to encapsulate the logic inside your GHPython components as much as needed and not input/output more than you have to. Alternatively you can wrap the data from one component to the next in something which won't expose the data to GH. A third option is to use the PointCloud class or even the Volvox pointcloud. Both should severely speed this up.

3) Of course multithread it once it you find the best solution for you (if it's still too slow ;)

Attached a file exemplifying some of this..

Edit: Didn't see Daniel's answer, using Plane.ValueAt(pt) method will be even faster than calculating it yourself via Python.

Attachments:

Hey, just saw your post...That is REALLY good to know! Thanks ;)

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service