BoundingBox doesn’t pass the plane used for its construction, so I wasn’t able to pass a proper ‘plane’ into the function. I constructed one through projections of BoundingBox’s .Min and Max coordinates.
ChaneBasis didn’t work out, because it appears it doesn’t exist in rhino3dm.
I tried to change it to PlaneToPlane reorientation instead:
def combined_bbox_center(geometries, plane):
to_plane = rhino3dm.Transform.PlaneToPlane(rhino3dm.Plane.WorldXY(), plane)
to_world = rhino3dm.Transform.PlaneToPlane(plane, rhino3dm.Plane.WorldXY())
combined = None
for geo in geometries:
copy = geo.Duplicate()
copy.Transform(to_plane)
bbox = copy.GetTightBoundingBox()
combined = bbox if combined is None else rhino3dm.BoundingBox.Union(combined, bbox)
if combined is None or not combined.IsValid:
return None
center_pt = rhino3dm.Point(combined.Center)
center_pt.Transform(to_world)
return center_pt.Location
Plane is obtained through:
bb_united_min = bounding_box_tight_united.Min
bb_united_max = bounding_box_tight_united.Max
bb_united_centre = bounding_box_tight_united.Center
bb_united_max.Z = bb_united_min.Z
print("Min:", bb_united_min)
print("Max projected:", bb_united_max)
bb_united_centre.Z = bb_united_min.Z
print("Centre:", bb_united_centre)
bb_united_plane = rhino3dm.Plane(bb_united_centre,bb_united_max,bb_united_min)
First of all, plane resulted in Box’s plane: | 42.4574,-1.79918,-0.693389 (origin) | 0.699048,0.715074,0 (x axis) | 0,0,0 (y axis) | 0,0,0 (z axis)
While the coordinates provided were as follows:
Centre: 42.4574,-1.79918,-0.693389 (origin)
Min: -110.943,-158.716,-0.693389 (y)
Max projected: 195.858,155.118,-0.693389 (x)
And the expected plane is: 42.4574,-1.79918,-0.693389 (origin) | -0.699049182945316,-0.715073590495052,0 (x axis) | -0.715073590495052,0.699049182945316,0 (y axis) | 0,0,-1 (z axis)
as shown in Grasshopper example below:
I thought maybe Rhino3dm confused get and set while obtaining coordinates:
bb_united_centre_Z = bb_united_centre.Z = bb_united_min.Z
bb_united_max_Z = bb_united_max.Z = bb_united_min.Z
print("BB test: ", bb_united_centre_Z, bb_united_max_Z, sep=" | ")
And it does: BB test: | 42.4574,-1.79918,-0.693389 | -0.693388621860773,
and you can’t set their classes like this, because Point3d() doesn’t accept Point3d().
bb_united_centre = rhino3dm.Point3d()
bb_united_max_Z = rhino3dm.Point3d()
Regardgless, print("BB test: ", bb_united_centre, bb_united_max, sep=" | ")
results in BB test: | 42.4574,-1.79918,-0.693389 | 195.858,155.118,-0.693389, so coordinates are fine.
The coordinates immediately get passed to the Plane() constructor,
bb_united_plane = rhino3dm.Plane(bb_united_centre,bb_united_max,bb_united_min)
Swapping coordinates results in:
Box’s plane: | 42.4574,-1.79918,-0.693389 | -0.699048,-0.715074,0 | 0,0,0 | 0,0,0
and doesn’t affect the transformation.
It would seem the issue appears during Plane()'s calculations.