TITLE: Parametrizing the square spiral
QUESTION [11 upvotes]: Related to this question concerning number spirals I have another one, more specific.
While it is rather easy to arrange the natural numbers along an Archimedean spiral by
$$x(n) = \sqrt{n}\cos(2\pi\sqrt{n})$$
$$y(n) = \sqrt{n}\sin(2\pi\sqrt{n})$$
it's much more difficult to arrange them along a square spiral by a closed formula. It's very easy to construct the square spiral algorithmically ("go along straight lines and always turn to the right if possible") but I'm totally stuck how the functions $x(n),y(n)$ would look like as formulaic expressions. The only thing I'm quite sure about is that they will make use of the square root function - but how are the "radii" and the turns coded?
This is how the two spirals look like (the Archimedean spiral being appropriately scaled and rotated to align the square numbers):

And here you can see them being morphed into each other.
Can anyone give me a hint (or the solution)?

REPLY [3 votes]: By adapting the formula found at A174344 to be non-recursive using summation notation, you may get the following:
$$x(n) = \sum_{k=1}^{n} \sin(\frac{\pi}{2}\left \lfloor \sqrt{4k-3} \right \rfloor)$$
$$y(n) = \sum_{k=1}^{n} \cos(\frac{\pi}{2}\left \lfloor \sqrt{4k-3} \right \rfloor)$$
You can see this in action here on Desmos.
$(x(n),y(n))$ generates a clockwise square spiral beginning in the $+x$ direction. By negating one or both and/or swapping $x(n)$ and $y(n)$, you can create different orientations of the square spiral. The orientation in your example and on the Desmos graph use $(x(n),-y(n))$.