开发者

Translating a rectangle's coordinates

I have two applications, one that creates a rectangle, and output's it's left,top,width,height and rotation angle, and another that draws the rectangle to the screen.

Application1 (writer) uses the top, left as the origin for rotation.

Application2 (reader) uses the center as the origin for rotation.

I'm trying to get a deltaX, and deltaY so that I can draw the rectangle, rotate it about the origina, and use a built in translate me开发者_高级运维thod, to shift the rectangle into position.

I know that a points rotation can be calculated as follows:

x' = x*cos(theta) - y*sin(theta) y' = x+sin(theta) + y*cos(theta)

But, with that, I can't seem to figure out the actual delta values needed for the translate method.

In the image below, the white rectangle is drawn using top/left as the rotation point, while the green rectangle is drawn using center as the rotation point. I'd like to shift the green rectangle onto the white one.

(0,0)

Translating a rectangle's coordinates


You have to translate by:

Translating a rectangle's coordinates

Development:

  • In application 1, the top left vertex of a rectangle shall be

    Translating a rectangle's coordinates

    .

  • Since application 1 rotates rectangles about the top left vertex, their rotated position coincides:

    Translating a rectangle's coordinates

  • Application 2 uses center coordinates, which relate to top-left point in application 1 as follows:

    Translating a rectangle's coordinates

  • To calculate the rotated top-left vertex in application 2, we apply the rotation matrix R:

    Translating a rectangle's coordinates

  • So the translation vector T is (substituting equations above):

    Translating a rectangle's coordinates

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜