4
$\begingroup$

Similarly to how cantor pairing function works by pairing two numbers >=0 to 1 unique number >=0, and where the ordering goes zig zag like dovetailing, is there a way to map numbers including negative ones to unique numbers but for a spiral pattern?

In this image, the center is centered on (0,0). Given a square of odd length, i.e. 1, 3, 5, 7..., does there exist a function that can map the coordinates to the ones indicated in red font? Like (0,0) -> 0, (1, -2)->11?

Does anyone know?

Thanks

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ Are you asking for an explicit function that describes the mapping? $\endgroup$
    – MT_
    Jul 15, 2016 at 17:53
  • $\begingroup$ I would prefer an explicit formula if it exists. $\endgroup$
    – omega
    Jul 15, 2016 at 17:55

2 Answers 2

2
$\begingroup$

Given two integers $x$ and $y,$ here's a formula for the position $f(x,y)$ of the pair $(x,y)$ in the spiral sequence.

First let $s$ be whichever of $x$ and $y$ has greater absolute value. (If $x$ and $y$ have the same absolute value, just set $s=x.$) Then

$$f(x,y)=\begin{cases} 4s^2-x+y, &\text{if }s \ge 0,\\ 4s^2+(-1)^{\delta_{s,x}}(2s+x+y), &\text{if }s < 0. \end{cases}$$

Here $\delta_{s,x}$ is the Kronecker delta, which is $1$ if $s=x,$ and $0$ otherwise.

$\endgroup$
0
$\begingroup$

Of course there is such a function. You've just "defined" it by your picture! The fact that we might not know how to write it as a formula can by no means endanger the pure existence of the mapping.

$\endgroup$
1
  • 4
    $\begingroup$ The OP's question seems to be "Is this picture valid?" Your answer asserts that it is, but doesn't really address the question of why... As such, I don't think that your answer really addresses the question. $\endgroup$
    – Xander Henderson
    Dec 12, 2017 at 0:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .