# Calculating AABB's Origin

I can't work out how to find the position in which my AABB should be corresponding to my object.

-
The code in that picture is a little tough to read. Maybe I'm just older today than I have been previously... Consider copy/pasting it here to make it easier to read. – chaosTechnician Jun 10 '12 at 21:08

I assume you're using that code in the picture and it's giving you the incorrect box shown on the right? The algorithm looks sound enough to find the minimum and maximum `X` and `Y` values in your list so are you sure your vertex list is properly representing the triangle you're trying to determine a box for?

It looks like your bounding box is the right size, just shifted in the `X` direction. Are you sure that the vertex locations you're sending are accurate for that triangle? Have you tried shifting it in different directions to make sure the disparity is consistent? What have you tried?

Additionally, I notice you aren't setting your `AABB` rectangle to an initial value, that's going to potentially cause a problem when setting it for some objects. Whether that's the problem here or not, I'm not sure. I'd recommend setting `AABB` initially to represent the first vertex you send in--so you know it starts with valid data, then iterating through the rest of the list: `AABB = verts[0]` (or, if Flash is different, however you'd do it there).

-
All the code does is calculate the extents of the vertices and puts them into a Rectangle object. I need to work out the position of the AABB relative to the vertices. Look: imgur.com/S16xY Notice the centre / position of the box changes as it rotates. – SyntheCypher Jun 10 '12 at 21:33
Yes, for a list of vertices, the extents are the corners of an AABB surrounding it. Here's the Wikipedia link on bounding volumes, check the paragraphs about Bounding Boxes. AABBs aren't intended to be rotated, perhaps you're looking for a different kind of bounding box? – chaosTechnician Jun 10 '12 at 22:05
BB stands for bounding box and I want an Axis-Aligned Bounding Box... – SyntheCypher Jun 10 '12 at 23:47
And the "AA" is Axis Aligned, meaning they're not intended to be rotated. If you want to rotate it with the object, consider an oriented bounding box. If you don't want it to rotate, I'm not sure what the problem is. – chaosTechnician Jun 11 '12 at 2:31

You could create the AABB using two points, from the bottom left of the triangle as a minimum point, and the maximum point being the top right, i.e. x is the point on the right, and y is the top left point.

-
This is all good and well but it still won't give me the position the AABB needs to be relative to the polygon. – SyntheCypher Jun 10 '12 at 21:28
@SyntheCypher it will, the bottom left corner of the triangle will be the AABBs origin, or (0,0). – Soapy Jun 10 '12 at 21:35