GetBoundingBox Aligned to Plane

I am trying to get the bounding box of a curve aligned to a plane. If I use GetBoundingBox(True), the boxes show up in the correct location. However if I use GetBoundingBox(plane) or GetBoundingBox(transform). The bounding box is always in the wrong place.Do I need to transform the bounding box after it is created?

Thanks!

Hi Ryan,

Can you post all of your code and your geometry?

Thanks,

– Dale

Also, this is through Grasshopper Python so that might be causing the error as well. See below for some screen shots. Here is the code:

import Rhino
if len(boundaries) != len(planes):
    raise ValueError("ERROR: Boundary and Plane lists must have the same number of items!")

polylines = []

for i, b in enumerate(boundaries):
    p = planes[i]
    xform = Rhino.Geometry.Transform.ChangeBasis(p, Rhino.Geometry.Plane.WorldXY)
    bb = b.GetBoundingBox(True)
    polylines.append(bb)

You can see below that GetBoundingBox(True) is working just fine.

You can see in the next two images that both GetBoundingBox(Plane) and GetBoundingBox(Transform) are close but 1 box is located in the wrong location and rotation.
<img src=β€œhttps://aws1.discourse-cdn.com/mcneel/uploads/default/original/3X/5/8/588640284d8fb2c1527a34b3bec0fe42db12014b.jpg” width=β€œ690” heigh t=β€œ431”>

Finally, if I use the orient command from grasshopper to position the bounding boxes from the WorldXY plane to the new plane it is fixed But when I try to transform the boxes myself, they are incorrect(last image). It is close but not quite right.

Does this help at all? The last image is close… but it seems to distort the bounding box as it transforms it.

Hi Ryan,

Keep in mind that a BoundingBox is just a struct that contains two points: the min and max points. Its’ pretty hard to orient 2 points to anything but the world. So, you will want to get the corners of the bounding box and transform them.

You might want to consider a bounding box calculator that looks more like this:

def MyBoundingBox(geometry, plane=None):
    if plane is not None:
        # Get plane aligned bounding box
        bbox = geometry.GetBoundingBox(plane)
    else:
        # Get world x-y plane aligned bounding box
        bbox = geometry.GetBoundingBox(True)
    # Get bounding box corner points
    corners = list(bbox.GetCorners())
    # Transform from plane coordinates to world coordinates, if needed
    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

– Dale

1 Like

Well, I think I had the same realization as you did last night. I finally figured out that a bounding box isnt so much a β€œbox” as it is data representing a box. In this case 2 points. Thanks for all the help!