2
$\begingroup$

I have rectangle with co-ordinates(x1,y1) and (x2,y2) and I have to rotate the rectangle an amount of θ about it centre using Rotation Matrix

 |  cosθ  sinθ |
 | -sinθ  cosθ |

I need to find the co-ordinates of bounding rectangle after rotation.

Before rotation

0,0
 |"""""""""""""""""""""""""""""""""""""""""""|
 |                                           |
 |  x1,y1                                    |
 |       |"""""""""""""|                     |
 |       |             |                     |
 |       |             |                     | 
 |       |             |                     |
 |       """""""""""""" x2,y2                |
 |                                           |
 |                                           |
  """"""""""""""""""""""""""""""""""""""""""" W,H

After rotation

 0,0
     |"""""""""""""""""""""""""""""""""""""""""""|
     |           ?,?                             |
     |            |""""/\"""""|                  |      
     |            |   /   \   |                  |
     |            |  /      \ |                  |
     |            | /        /|                  |
     |            |/        / |                  |
     |            |\       /  |                  |
     |            |  \    /   |                  |
     |            |    \ /    |                  |
     |             """""""""""  ?,?              |
     |                                           |
     |                                           |
      """"""""""""""""""""""""""""""""""""""""""" W,H

Is there any general equation for finding the co-ordinates of bounding rectangle?.

Thanks....

Haris.

$\endgroup$
1
$\begingroup$

For each of the four original corners: $$ (x_1,y_1), (x_1,y_2), (x_2,y_1), (x_2,y_2) $$ use the rotation matrix to obtain four new corners. Then to obtain the two ordered pairs that define your bounding rectangle, let one ordered pair have the minimum $x$ and $y$ values out of all the new corners and let the other ordered pair have the maximum $x$ and $y$ values.

$\endgroup$
  • $\begingroup$ Hi as you suggested I found four co-ordinate using the equation X=xcosθ+ysinθ and Y=-xsinθ+ycosθ. It is working fine up to θ=90,but when θ exceeds 90 degree bounding rect moving away from rotated rectangle.This is happening up to 360 degree and then for the next 90 degree it's fine. Any suggestion. $\endgroup$ – Haris Nov 7 '13 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.