Get rotation center of rectangle

◇◆丶佛笑我妖孽 提交于 2019-12-13 12:23:04

问题


Given the bounding box, relative rotation center, and rotation angle of a rectangle I need to find the absolute rotation center of the rectangle. Here is an image (I wouldn't mind if someone improved it):

I hope that is clear enough. I need the x and y coordinates of the red dot. I've been working on this for some time now and I am lost with my trivial knowledge of trig. :/

回答1:


If the angle of rotation is a shown negative above, then the coordinates of the red dot are:

rx = x + rcx*COS(a) - rcy*SIN(a)
ry = y - (w-rcx)*SIN(a) + rcy*COS(a)

and remember to convert degrees to radians before taking SIN() or COS().

Example: (x,y)=(80,60), (w,h)=(20,60) and a=-15°, with (rcx,rcy)=(15,30)

rx = 80 + 15*COS(-15°)-30*SIN(-15°)      = 102.25
ry = 60 - (20-15)*SIN(-15°)+30*COS(-15°) = 90.27

Here is an output from GeoGebra of the calculation (with negative y-axis)



来源:https://stackoverflow.com/questions/11193442/get-rotation-center-of-rectangle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!