找到旋转矩形的边界矩形 [英] Find the Bounding Rectangle of Rotated Rectangle

查看:209
本文介绍了找到旋转矩形的边界矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有矩阵的坐标(x1,y1)和(x2,y2),我必须使用旋转矩阵将矩形旋转θ的中心值。

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

我需要找到旋转后的边界矩形的坐标。



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

轮播

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

有没有找到边界矩形坐标的一般公式? b
$ b

谢谢....

Haris。

解决方案Point(x 1 ,y 1 )旋转到(x 1 cos < - >; - y 1 sin(θ1,sinθ)+ y 1cosθ),而点(x 2,y 2,..., sub> 2 )旋转到(x 2cosθ-y 2 sin +θ2,x 2sinθ+其他两个点可以相应计算。

边界矩形的坐标是(x 3,y 3)和(x 4,y 4),其中x 3是所有新的x坐标中最小的,y <3>是所有新y坐标中最小的,x <4>是所有新x坐标中最大的,y 4 >所有新的最伟大的y坐标。

哪个角落产生最小的x(依此类推)取决于您的角度或旋转角度。对于0°以下的角度,到90°,x 3将来自(x 1,y 1),所以x 3 = x 1 cosθ - y 1 sin&theta ;.对于90°和90°以下的角度,到180°,它将来自(x 2,y 1)等等。
因此,要么根据旋转角度决定使用哪些点,要么只是取所有x和y中的最小者和最大者。





但我认为您应该在 https://math.stackexchange.com/ 上提出此问题


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.

解决方案

Point (x1, y1) rotates to (x1 cos θ - y1 sin θ, x1 sin θ + y1 cos θ), while point (x2, y2) rotates to (x2 cos θ - y2 sin θ, x2 sin θ + y2 cos θ). The other two points can be calculated accordingly.

The coordinates of the bounding reactangle are (x3, y3) and (x4, y4), where x3 is the smallest of all new x coordinates, y3 the smallest of all new y coordinates, x4 the greatest of all new x coordinates and y4 the greatest of all new y coordinates.

Which of the corners produces the smallest x (and so on) depends on your angle or rotation. For angles from 0° to 90°, x3 will come from (x1, y1), so x3 = x1 cos θ - y1 sin θ. For angles from 90° to 180°, it will come from (x2, y1), and so on. So either you decide which points to use based on your angle of rotation, or you just take the smallest and greatest of all x's and y's.


But I think you should probably ask this on https://math.stackexchange.com/

这篇关于找到旋转矩形的边界矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆