# How do I get extents in my mesh

I am creating a AABB for collision detection. I need to calculate the extents for my model and also update them when my model moves. I calculate my min and max when I create my mesh and I use my position to reference the center.

Could someone please show me how to get the extents either with my min and max vectors or with an array of vertices.

Actually for more clarification I tried this

public Vector3f getMin() {
return Vector3f.sub(pos, extents, null);
}

public Vector3f getMax() {
}


The problem is that everything seems to be centered around the origin(0,0,0). The position is the position of the entity the AABB represents.

• So just to clarify: You already have the min & max positions, and you're asking how to calculate the size of a bounding box from those?
– user35344
Apr 6, 2018 at 16:07
• @Tyyppi_77 Yes I am Apr 6, 2018 at 16:33
• How are you calculating extents? Why is the same method twice there? How is this code not working? Have you tried rendering/printing out the AABB? Are you sure that your min & max positions are calculated correctly?
– user35344
Apr 6, 2018 at 16:56
• @Tyyppi_77 Here is how I caluculate extents this.extents = Vector3f.sub(max,min,null); and everything is centered around the origin. Apr 6, 2018 at 17:05

The size of the box that covers the whole mesh is simply the difference between the max and the min position: vec3 size = max - min;.
Now from that you can get the extents simply by halfing the size: vec3 extents = size * 0.5f;