# Re-scaling a rectangle based on the rotation of its content

As you might have noticed in the video in my earlier post, the bounding box of the sprite is scaling based on the rotation. This is useful as it ensures that even if the content is rotated, it is always within the bounds of the rectangle. To illustrate this, take a look at the following photos:

When we rotate the blue square, its bounds increases to the square in green. This is what we are trying to compensate for. The following formula gives us the delta x and y from the origin point.

Using this formula, we find that *dx’ = 4.24* and* dy’ = 4.24*. Please note that this formula will work for any sizes, I’m just using a square for simplicity. By applying this to code, we get the following in C#:

## Comments

## Marcus Specht

on Sep 02, 2013Reply

Hey Håvard , nice one… thx. But why do you calculate float rot = angle % (float)Math.PI / 2.0f; without using it afterwards?

## Nex

on Sep 02, 2013Reply

Hi Marcus, thank you for noticing! I should actually have omitted that, as it is part of an older version of the code where the corners were calculated by using an interpolation-like expression instead. It worked, but was not very intuitive and had performed a little worse if I remember correctly. If you are interested, I can hook you up with the code. I’ll get this post cleaned up shortly. Thanks again ;)

## Leave a comment