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)
You have to translate by:
Development:
In application 1, the top left vertex of a rectangle shall be
.Since application 1 rotates rectangles about the top left vertex, their rotated position coincides:
Application 2 uses center coordinates, which relate to top-left point in application 1 as follows:
To calculate the rotated top-left vertex in application 2, we apply the rotation matrix R:
So the translation vector T is (substituting equations above):
精彩评论