Skip to content
Advertisement

How to calculate a bounding box for a rectangle rotated around its center?

I am looking to calculate the bounding box of a rectangle rotated around its center. I have read this question and while MarkusQ’s answer works in general, it is not efficient enough for my needs. I am trying to get Troubadour’s answer working, but it seems to only work when the origin of rotation is around a corner, not the center.

Is it possible to adapt his solution to work with rectangles that have their origin of rotation around their center?

I’ve developed a full recreation of the problem below:

JavaScript
JavaScript
JavaScript

As you can see, the bounding box rectangle is not correct. Here’s what it currently looks like, and what it should look like:

enter image description here

Advertisement

Answer

Size of bounding box (description here)

JavaScript

Having rXCenter, rYCenter, you can find get bounds coordinates

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement