Parametric form of square

Lets consider a square of size $2 \times 2$ in a rectangular coordinate system, where each side is a part of the lines $x = \pm 1, y = \pm 1$. Then you can define

$$\gamma(\alpha) = \begin{cases} (1,\tan(\alpha)) & \alpha \in [-\pi/4 , \pi/4] \\ (\cot(\alpha),1) & \alpha \in [\pi / 4, 3 \pi /4 ] \\ (-1,-\tan(\alpha)) & \alpha \in [3\pi/4 , 5\pi/4] \\ (-\cot(\alpha),-1) & \alpha \in [5\pi/4, 7\pi/4] \end{cases}$$

which describes the parametric path of square shape, with the angle as parameter.


For using it in a program following works also very well: Define $\varphi(x) = \max(0, \min(1, 3/2 - \vert x \vert))$. Then

$\gamma: [0, 4] \to \mathbb R^2$ with $t \mapsto (\varphi(t-3/2), \varphi(t-5/2))$

works very well and doesn't need any expensive evaluations of trigonometric functions.

Note that $\gamma$ traces the boundary of $[0,1]^2$.


$$f(\alpha) = \sec(\alpha- \frac \pi2 \lfloor \frac {4\alpha + \pi}{2\pi}\rfloor ) $$ Where $f$ is the function that gives the distance between the center of the square and a point of the square at the $\alpha$ angle

Giving us $$\begin{cases} \cos(\alpha) f(\alpha) \frac X2 +x_0\\ sin(\alpha) f(\alpha) \frac Y2 + y_0\\ \end{cases}$$

where X and Y the length and height respectivly and $x_0$ and $y_0$ are the coordonated of the square.