Rational Spiral

Author

Eric W. Weisstein
March 16, 2008

This notebook downloaded from http://mathworld.wolfram.com/notebooks/PlaneCurves/RationalSpiral.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/RationalSpiral.html.

©2008 Wolfram Research, Inc. except for portions noted otherwise

Code

spiral[n_]:=spiral[n,2]

Szudzik

spiral[n_,1]:={1,1}*Sum[(-1)^((#-{0,1})/2)*Mod[#+{1,0},2]&[Ceiling[2*Sqrt[i]]-2],{i,n}]

spiral[n_,2]:={1,1}*Sum[(-1)^(#/2)*Mod[#+1,2]&[Ceiling[2*Sqrt[i]]-{2,3}],{i,n}]

Wolfram

spiral[n_,3]:=With[{m=Round[Sqrt[n]]},
(-1)^m({-Ceiling[m/2],Floor[m/2]}+(m^2-n) (Sign[m^2-n]{1,-1}+1)/2)]

Tafjord

spiral[n_,4]:=(-1)^#({1,-1}(Abs[#^2-n]-#)+#^2-n-Mod[#,2])/2&[Round[Sqrt[n]]]

Plots

Table[spiral[n],{n,0,55}]

ListPlot[s=Table[spiral[n],{n,0,55}],PlotJoined->True,Axes->False,AspectRatio->Automatic,Epilog->{{GrayScale[.5],Line[{{-5,0},{5,0}}]},PointSize[.02],RGBColor[1,0,0],Point/@s}]

Show[GraphicsArray[Table[ListPlot[Table[spiral[n,k],{n,0,55}],PlotJoined->True,Axes->False,AspectRatio->Automatic,DisplayFunction->Identity],{k,4}]]]