# Finding bounding width, height, depth of a mesh?

Hi, I wonder if there’s any easy solution to find out the bounding width, height, depth of a mesh.
In ofPolyline, there’s getBoundingBox() method, but is there any similar method for calculating 3d bounding box in ofMesh?

There are two main methods, Axis Aligned Bounding Box (AABB) or Object Oriented Bounding Box (OOBB): find the algorithms here

AABB

OOBB

1 Like

Thanks Hennio.

I think this one works for me. it just returns bounding width, height, depth of ofMesh.

``````ofVec3f getMeshBoundingBoxDimension(const ofMesh &mesh) {

auto xExtremes = minmax_element(mesh.getVertices().begin(), mesh.getVertices().end(),
[](const ofPoint& lhs, const ofPoint& rhs) {
return lhs.x < rhs.x;
});
auto yExtremes = minmax_element(mesh.getVertices().begin(), mesh.getVertices().end(),
[](const ofPoint& lhs, const ofPoint& rhs) {
return lhs.y < rhs.y;
});
auto zExtremes = minmax_element(mesh.getVertices().begin(), mesh.getVertices().end(),
[](const ofPoint& lhs, const ofPoint& rhs) {
return lhs.z < rhs.z;
});
return ofVec3f(xExtremes.second->x - xExtremes.first->x,
yExtremes.second->y - yExtremes.first->y,
zExtremes.second->z - zExtremes.first->z);
}``````
2 Likes

Perfect! +1 for the use of std::minmax_element

1 Like