绘制一个旋转的矩形

绘制一个旋转的矩形

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

问题描述

我意识到这可能是更多的数学问题。



为了绘制矩形的线条,我需要解决他们的问题。
我在(x,y)处有一个矩形中心,并带有一个定义的宽度和高度。


要在顶部(角度= 0)的非旋转矩形上查找蓝色点$ b $ / b / b / b / b / b它是

$ b $ UL =(x-Width / 2),(y + height / 2)

UR =(x + Width / 2),(y + height / 2)

LR =(x + Width / 2),(y-height / 2)

LL =(x-Width / 2),(y -height / 2)



如果角度不是0,我该如何找到点?



预先致谢。





更新:尽管我的照片中有(0,0)作为中心点可能中心点不在该位置。

首先将中心点转换为0,0



X'= Xx

Y'= YY
旋转一个角度A

X'=(Xx)* cos A - (Yy)* s在A中

Y'=(Yy)* cos A +(Xx)* sin A

再次将中心点转换回x,y

x'''=(Xx)* cos A - (Yy)* sin A + x



Y''=(Yy)* cos A +(Xx)* sin A + y

因此计算所有4点具有以下变换的(X,Y)...

X'''=(Xx)* cos A - (Yy)* sin A + x



Y''=(Yy)* cos A +(Xx)* sin A + y

其中x,y是矩形的中心点和X,Y是角点
当角度为0时,您还没有正确定义角点,正如我在注释中给出的。



替换后您将得到

  UL = x +(宽度/ 2)* cos A  - (Height / 2 )* sin A,y +(Height / 2)* cos A +(Width / 2)* sin A 
UR = x - (Width / 2)* cos A - (Height / 2)* sin A, y +(高度/ 2)* cos A - (宽度/ 2)* sin A
BL = (宽度/ 2)* cos A +(高度/ 2)* sin A,y - (高度/ 2)* cos A +(宽度/ 2)* sin A
BR = x - 2)* cos A +(Height / 2)* sin A,y - (Height / 2)* cos A - (Width / 2)* sin A

我认为这适合您的解决方案。


I realize this might be more of a math problem.

To draw the lines for my rectangles I need to solve for their corners.I have a rectangle center at (x,y) With a defined Width and Height.

To find the blue points on a non rotated rectangle on top (angle = 0)It is

UL = (x-Width/2),(y+height/2)
UR = (x+Width/2),(y+height/2)
LR = (x+Width/2),(y-height/2)
LL = (x-Width/2),(y-height/2)

How do I find the points if the angle isn't 0?

Thanks in advance.


Update: although I have (0,0) in my picture as the center point most likely the center point won't be at that location.

解决方案

First transform the centre point to 0,0

X' = X-x

Y' = Y-y

Then rotate for an angle of A

X'' = (X-x) * cos A - (Y-y) * sin A

Y'' = (Y-y) * cos A + (X-x) * sin A

Again transform back the centre point to x,y

X''' = (X-x) * cos A - (Y-y) * sin A + x

Y''' = (Y-y) * cos A + (X-x) * sin A + y

Hence compute for all 4 points of (X,Y) with following transformation

X''' = (X-x) * cos A - (Y-y) * sin A + x

Y''' = (Y-y) * cos A + (X-x) * sin A + y

where x, y are the centre points of rectangle and X,Y are the corner pointsYou have n't defined correctly even the corner points when Angle is 0 as I have given in the comments.

After substituting you will get

UL  =  x + ( Width / 2 ) * cos A - ( Height / 2 ) * sin A ,  y + ( Height / 2 ) * cos A  + ( Width / 2 ) * sin A
UR  =  x - ( Width / 2 ) * cos A - ( Height / 2 ) * sin A ,  y + ( Height / 2 ) * cos A  - ( Width / 2 ) * sin A
BL =   x + ( Width / 2 ) * cos A + ( Height / 2 ) * sin A ,  y - ( Height / 2 ) * cos A  + ( Width / 2 ) * sin A
BR  =  x - ( Width / 2 ) * cos A + ( Height / 2 ) * sin A ,  y - ( Height / 2 ) * cos A  - ( Width / 2 ) * sin A

I think this suits your solution.

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

08-31 10:44