2
$\begingroup$

In the image below there are two rectangles of known width (w) and height (h), that rotate by a known angle (a) around their centres. I need to solve for n.

I've tried the following on squares:

n =  sqrtf(powf(w, 2.0f) + powf(w, 2.0f))/2;

and where ang equals the transform angle:

n = (h-w) * (fabsf(ang) / 90) / 2;

but both attempts fail between angles 0 and -90.

I've considered calculating all the angles (e.g. b) within the triangle of n, but without knowing any of the lengths I'm struggling. I need the equation for a swiping animation in a mobile app.

w = 320
h = 568
a = -20

enter image description here

EDIT: I've included a second image to show the changing shape of the triangle to a quadrilateral to a rectangle (at 90 degrees). Is it fair to assume the solution would need to include more than just triangle trig?

enter image description here

1 Answers 1

2

The lower right corner has the starting coordinates $(x_0, y_0)=(\frac{w}{2},-\frac{h}{2})$. After a rotation about the rectangle center of $\alpha=a*\frac{\pi}{180}$ it will have the coordinates $(x_a,y_a)$ where $$x_a=x_0*cos(\alpha)-y_0*sin(\alpha)$$

and $$y_a=x_0*sin(\alpha)+y_0*cos(\alpha)$$

Hope this helps.

  • 0
    I don't follow the solution - would it still work when the triangle becomes a quadrilateral?2017-01-12
  • 0
    Can I know that the radius equals the hypotenuse of the small triangles drawn above? My brain hurts.2017-01-12
  • 2
    The solution works for any angle and doesn't depend on any of the triangles or quadrilaterals in your drawings. It is simply how coordinates change when undergoing a rotation. You can find the equations [here](https://en.wikipedia.org/wiki/Rotation_(mathematics)#Two_dimensions) or on page 8 [here](http://www.uio.no/studier/emner/matnat/ifi/INF3320/h03/undervisningsmateriale/lecture3.pdf).2017-01-12