# Howto access a model's dimensions from inside a ModelPlugin

Hi guys,

i have implemented a model plugin, which is automatically instantiated embedding a sdf in my simulated world. With the use of a model ptr i should have, as the function name indicates, access to the collision box by

math::Box GetCollisionBox() const


Unfortunately, this function always returns a zero vector for the dimension of this box, though Gazebo's collision view in the GUI displays the correct dimension. Another method, which is provided by the model pointer,

math::Box GetBoundingBox() const


provides values of which it isn't obvious how they are calculated, related to the sdf definition of the model. Having a look at the current code in Model.cc on bitbucket, following up l.748, it seems to be calculated iterating through all links, aggregating over all the bounding boxes of the links.

So my question is, how can the bounding box be specified the right way in order to derive the appropriate dimensions of a model?

Best regards!

edit retag close merge delete

Sort by » oldest newest most voted

I believe you're looking for information on a model's geometry. First, let's understand the structure of a model in Gazebo.

• A model is a collection of links

• A link can contain several collisions

• Each collision has a shape. The shape can be something like a box, cylinder, sphere or a mesh.

So if you have a model which you know has a single link, which has a single collision, which is a sphere, you can get to its radius like this:

auto link = model->GetLink();


auto collision = link->GetCollisions()[0];

3. Collision::GetShape

auto sphereShape = boost::dynamic_pointer_cast<physics::SphereShape>(collision->GetShape());


auto radius = sphereShape->GetRadius();


Regarding the rest of your question:

• I couldn't find the GetCollisionBox function in Gazebo, where did you get it from?

• As for GetBoundingBox, it represents the world axis-aligned bounding box [1]. That is the smallest box aligned with the world which fully contains the model.

more