I want to find if a point (x,y)where x,y integers satisfy the spiral square. (0,0) (0,1) (1,1) (1,2) (0,2) (-1,2) (-2,2) (-2,1) (-2,0) ans so on.....
How do I do it? I want the logic for a java or c++ function.
以下は、いくつかの疑似コード ロジックです。
Start with x=0, y=0, dist=0, direction=1
Loop
x += (++dist * direction)
WritePoint(x,y)
y += (++dist * direction)
WritePoint(x,y)
direction *= -1
LoopEnd
そこから取ってください。
次の操作を行います。
(operator)(operation)(amount)
ここで、演算子は x,y,x,y,... (そのためには % 演算子を使用) のように変わり、操作は +,+,-,-,+,+,-,-,+,+...(再びそのためには % 演算子を使用します)、量は 1,2,3,... のように変化します