BoundingBox Center

hi, how can I get the Bounding Box center?

rs.BoundingBox returns a list of eight 3D points that define the bounding box, So you can compute the average of these points:

import rhinoscriptsyntax as rs
from functools import reduce
bbox = rs.BoundingBox(g)
a = reduce(lambda a, b: a + b, bbox) / len(bbox)

using Rhino.Geometry.BoundingBox you can directly get the bounding box and it’s center like this:

bbox = g.GetBoundingBox(True)
a = bbox.Center

BoundingBoxCenter.gh (4.9 KB)

1 Like

tanks mahdiyar :heart_eyes:

Using BoundingBox.PointAt(0.5,0.5,0.5) would be another option

1 Like

To add a slightly faster option: average just the min max points:

import rhinoscriptsyntax as rs
bbox = rs.BoundingBox(g)
a = (bbox[0] + bbox[6]) * 0.5
3 Likes

A lazy programmer, such as myself, might just use BoundingBox.Center.

– Dale

2 Likes