Parametrizing arbitrary rectangular spirals

47 Views Asked by At

Parametrizing a square spiral can be done by modifying the equations found in this OEIS entry

$$ k(n) = \frac{\pi}{2}\left \lfloor \sqrt{4n-3} \right \rfloor $$ $$ x(n) = \sum_{k=1}^{n} \sin(k(n)) $$ $$ y(n) = \sum_{k=1}^{n} \cos(k(n)) $$

However this assumes a square, rectangular spirals see below, are not covered:

5x3: 
12  4   3   2   11
13  5   0   1   10
14  6   7   8    9

4x5:
23  22  21  20
15  14  13  12
 4   3   2  11
 5   0   1  10
 6   7   8   9
16  17  18  19

Is it possible to parameterize the positions of an arbitrary rectangular spiral with width $w$ and height $h$ in a similar way?

For example in the 5x3 case shown above for each integer $n$ $x(x)$ would give: 0, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, -2, -2, -2. and $y(n)$ would give 0, 0, -1,-1, -1, 0, 1, 1, 1, 1, 0, -1, -1, 0, 1.