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:
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):
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!
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
The
set samples 2000tells 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.