6

What is the appropriate parametric equation of the boundary of a square? For example, the unit circle has a parametric equation $x(t)=\cos(t)$ and $y(t)=\sin(t)$.

Janak
  • 1,065
  • 1
    See also http://math.stackexchange.com/a/279209/589. – lhf Oct 17 '14 at 17:04
  • 3
    $$[0,2\pi) \ni t;;\mapsto;; (x(t),y(t)) = !\left(\frac{\cos(t)}{\rho(t)},\frac{\sin(t)}{\rho(t)}\right) \quad\text{ where }\quad \rho(t) = \max\big(|\cos(t)|,| \sin(t)|\big)$$ – achille hui Oct 17 '14 at 17:09
  • The above is a parametric equation of circle not a square. Thank you. – Janak Oct 18 '14 at 07:28
  • @Janak Strange remark ; the parametric representation given by achille hui is indeed a parametric representation of a square. – Jean Marie May 05 '23 at 20:29

5 Answers5

7

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$.

flawr
  • 16,533
  • 5
  • 41
  • 66
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.

1

A parametrization of a straight line from $P$ to $Q$ is $r(t)=tP + (1-t)Q$ as $t$ goes from $0$ to $1$. Four of these pieces with suitable start and stop values for $t$ will take you round the square for $t$ going from $0$ to $4$.

Paul
  • 1,482
0

You can just break it down into 4 line segments: $c(t)=(x(t),y(t))=$ $(t,0); 0\leq t\leq 1$

$(1, t-1); 1\leq t\leq 2$

$(3-t,1); 2\leq t\leq 3$

$( 0, 4-t); 3 \leq t\leq 4. $

MSIS
  • 725
0

Introduce a scaling factor r to the parameterization of the circle:
$x(t)=r(t)cos(t)$
$y(t)=r(t)sin(t)$
Then the following r gives a square with sidelenght 1
$r(t)=\frac{1}{\sqrt2 (|sin(t+\frac{\pi}{4})|+|cos(t+\frac{\pi}{4})|)}$
Or if you remove the phaseshift $\frac{\pi}{4}$ you get the scaling factor for a diamond.

$d(t)=\frac{1}{\sqrt2 (|sin(t)|+|cos(t)|)}$