trumank
trumank

Reputation: 2794

Get rotation center of rectangle

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. :/

Upvotes: 0

Views: 1273

Answers (1)

John Alexiou
John Alexiou

Reputation: 29244

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)

GeoGebra output

Upvotes: 3

Related Questions