Finding $(x, y)$ as a function of $n$ radians For a joystick thing in a game, I need to find where a line with an angle of $n$ radians intersects with a square of width and height of $2$ around the joystick with a radius of 1.

Right now I have a simple sin cos function that only gets the coordinates on the circle and not the square.
$$
f(n) = [\sin(n), \cos(n)]
$$
What function is used to find a vector of $x$ and $y$ as a function of $n$ radians that is on the square?
 A: The ray's intersection with the square will naturally depend on what side it intersects:
$$\begin{cases}
(1,\tan n)&-\frac\pi4\le n\le\frac\pi4\\
(\cot n,1)&\frac\pi4\le n\le\frac{3\pi}4\\
(-1,-\tan n)&\frac{3\pi}4\le n\le\frac{5\pi}4\\
(-\cot n,-1)&\frac{5\pi}4\le n\le\frac{7\pi}4
\end{cases}$$
This is done by taking $(\cos n,\sin n)$ (the order in the question body is wrong if it refers to $(x,y)$-coordinates) and then dividing by the larger coordinate to make it $\pm1$, leaving the transformed point on the square itself. The cases can be unified as
$$\left(\operatorname{clip}_{-1}^1\left(\frac{\cos n}{|\sin n|}\right),\operatorname{clip}_{-1}^1\left(\frac{\sin n}{|\cos n|}\right)\right)$$
with $\operatorname{clip}_a^b(x)$ referring to clipping $x$ between $a$ and $b$ and equal to $\min(\max(a,x),b)$. This can be further simplified to
$$\frac{(\cos n,\sin n)}{\max(|\cos n|,|\sin n|)}$$
A: While $(\cos n, \sin n)$ in the question gives the unit circle, expanding the circle by a suitable factor $r(n)$ (which depends on $n$) gives the square.
The factor $r(n)$ is related to $\sec n$ and $\csc n$:
$$\begin{align*}
r(n) &= \min\left(\left|\sec n\right|, \left|\csc n\right|\right)\\
&= \frac{1}{\max\left(\left|\cos n\right|, \left|\sin n\right|\right)}
\end{align*}$$
Then the point on the square would be
$$\begin{align*}
f(n) &= r(n)\cdot(\cos n, \sin n)\\
&= \left(\frac{\cos n}{\max\left(\left|\cos n\right|, \left|\sin n\right|\right)}, \frac{\sin n}{\max\left(\left|\cos n\right|, \left|\sin n\right|\right)}\right)
\end{align*}$$
