Grasshopper

algorithmic modeling for Rhino

I am having an issue creating bounding boxes using python and RhinoCommon. I have made a big post with lots of pictures and details:

http://discourse.mcneel.com/t/getboundingbox-aligned-to-plane/8174

Any thoughts on how to fix this?

Thanks!

Views: 2064

Replies to This Discussion

1. Create a bounding box with the transform/plane of the orientation you want.

2. Use the min/max points from that bounding box

3. Create a new box new box (plane, interval(min.x, max.x), interval(min.y,max.y), interval(min.z, max.z))

ANSWER:

Since a bounding box isnt actually a box but really just a volume of enclosed space, if we try to transform the bounding box it really just move the box then recalculates to bounding box. The better solution is to get the corner points of the bounding box and then transform the points themselves. You can see the working code below:

def GetBoundingBox(geometry, plane=None):
if plane is not None:
bbox = geometry.GetBoundingBox(plane)
else:
bbox = geometry.GetBoundingBox(True)
corners = list(bbox.GetCorners())
if plane is not None:
world = Rhino.Geometry.Plane.WorldXY
plane_to_world = Rhino.Geometry.Transform.ChangeBasis(plane, world)
for pt in corners:
pt.Transform(plane_to_world)
return corners

 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service