How to calculate rectangle 'chord' after rotation?

390 Views Asked by At

I am no mathematician so please forgive me for using wrong terms.

I am looking to calculate the length of a segment of a rectangle according to its rotation around one of its vertices. For instance:

After 30deg rotation

I'm interested in knowing the length of the red segment.

I came with a plot like this with a $30\times10$ rectangle (deg on absciss axis and length on ordinates axis):

Plot

It ressembles nothing that I am aware of. I made some searches on the Internet but failed to find functions that could look like it. My guess is I should use trigonometry since it depends on the rectangle properties (30 and 10) and the angle.

Any suggestion is more than welcome!

1

There are 1 best solutions below

3
On BEST ANSWER

You have a right triangle with sides $x$ and $y$, with $$\begin{cases} \frac{x}{h} = \tan(\varphi) \\ \frac{y}{w} = \tan(90° - \varphi) \end{cases} \iff \begin{cases} x = h \tan(\varphi) \\ y = w \tan(90° -\varphi) \end{cases}$$ except that $\lvert x \rvert$ is limited to at most $w^2$, and $\lvert y \rvert$ is limited to at most $h^2$; in other words, $$\begin{cases} x^2 = \min(w^2, h^2 \tan^2(\varphi)) \\ y^2 = \min(h^2, w^2 \tan^2(90° - \varphi)) \end{cases}$$ where $\min$ operator just picks the smaller one, limiting $x^2$ to at most $w^2$, and $y^2$ to at most $h^2$.

The desired length, $f(\varphi)$, is the length of the hypotenuse, $$f(\varphi) = \sqrt{x^2 + y^2}$$ i.e., in degrees: $$f(\varphi) = \sqrt{\min\left( w^2, h^2 \tan^2(\varphi) \right) + \min\left( h^2, w^2 \tan^2(90° - \varphi) \right) }$$ or, in radians: $$f(\varphi) = \sqrt{\min\left( w^2, h^2 \tan^2(\varphi), \right) + \min\left( h^2, w^2 \tan^2(\pi/2 - \varphi) \right) }$$

If you use Gnuplot, you can draw this using

set samples 2000
set xlabel "degrees"
minsqr(a, b) = (a*a <= b*b) ? a*a : b*b;
f(x) = sqrt( minsqr(w, h*tan(x)) + minsqr(h, w*tan(0.5*pi-x)))

h=10.0 ; w=30.0 ; plot [0:360] f(x*pi/180.0) notitle w lines

The set samples 2000 tells Gnuplot to calculate the function at two thousand points. Current displays are so large, and the default number of samples so small, that the curve might seem to have extra features otherwise.