18

I would like to plot a surface that looks something like this sand spiral.

But I really have no idea how. Ideally I would like to be able to express this as a function in cartesian coordinates. I'm not looking for the granularity or anything, I just want a smooth spirally surface.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
user41147
  • 355
  • 1
  • 6

6 Answers6

33

A manual way of doing it is:

Plot3D[With[{ϕ = ArcTan[x, y], r = Sqrt[x^2 + y^2]}, 
  0.3 Sin[2 π r + ϕ]]
  , {x, -5, 5}, {y, -5, 5}
  , BoxRatios -> Automatic, Mesh -> None, PlotPoints -> 25, MaxRecursion -> 4
]

Sand Spiral

The reasoning behind the code is as follows: We know we want to start with some ripples radiating outwards, something like

$$\mathrm{height}(r) = h_0 \sin(r).$$

Plot3D gives us the cartesian {x,y} coordinates though, where we can evaluate our function. So we first need to express radius $r$ and for completeness and later use also our polar angle $\phi$ in terms of {x,y} which, when we investigate or look it up we find:

$$r = \sqrt{x^2+y^2}$$ $$\phi = \arctan(y/x),$$

which leads us to

Plot3D[With[{ϕ = ArcTan[x, y], r = Sqrt[x^2 + y^2]}, 
  0.3 Sin[5 r]]
  , {x, -5, 5}, {y, -5, 5}
  , BoxRatios -> Automatic, Mesh -> None
  , PlotPoints -> 25, MaxRecursion -> 4
]

Radial ripples

Almost there!

Now what we see in the reference what is still missing in the simple outward ripples is that as we go around the center the ripples shift outwards, which means that, additionally to the radius we want the effective phase in the outward rippling to also grow with the polar angle.

$$\mathrm{height}(r,\phi) = h_0 \sin(a\,r+\phi).$$

Mathematically this depicts an Archimedean Spiral.

Also we can choose a different factor for the r part in the phase, $2\pi$ is only one arbitrary value. We can get steeper or more shallow spirals with different factors.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Thies Heidecke
  • 8,814
  • 34
  • 44
17

You may want to plot z(r, fi) = sin (r + fi)

p = 20;
Plot3D[
  Evaluate @ Sin @ Tr @ CoordinateTransform["Cartesian" -> "Polar", {x, y}], 
  {x, -p, p}, {y, -p, p}, 
  PlotPoints -> 100, BoxRatios -> Automatic
]

enter image description here

p = 30.;
n = 9 10^4;
pts = Catenate@Array[List, Sqrt[n] {1, 1}, {{-p, p}, {-p, p}}] + 
   RandomReal[.2, n];

MapThread[ Append, 
  {pts, 
   Sin @ Total[ CoordinateTransform["Cartesian" -> "Polar", pts], {2}]
  }
] //  Sphere[#, .2] & // Graphics3D[#, Lighting -> {{"Directional", 
  RGBColor[1, .7, .1], {{5, 5, 4}, {5, 5, 0}}}}] &

enter image description here

Kuba
  • 136,707
  • 13
  • 279
  • 740
  • I guess this is similar to mine, but I didn't recognize it at first. Nice texture, too. (+1) – Michael E2 Jun 21 '16 at 04:34
  • @MichaelE2 Thanks, not very efficient but I wanted to see how it looks :) Well, all are similar but each brings something, in this respect mine is the least educational :) – Kuba Jun 21 '16 at 06:12
  • Wow! I didn't really need the sandy effect but this is awesome! – user41147 Jun 21 '16 at 13:20
6

Here is another way that looks more like sand spirals with the tide coming in:

With[{d = 42, n = 150}, 
 ReliefPlot[
  Cos@Table[
    Through[(Abs + Arg)[x + I y]], {x, -d, d, d/n}, {y, -d, d, d/n}]]]

As a side note, if you want to see a physics phenomenon where such Archimedean spirals occur, you may find this link to my web page interesting.

Jens
  • 97,245
  • 7
  • 213
  • 499
4

Thies's solution is excellent. This was the best I could do with a logarithmic spiral:

With[{ψ = 87°}, 
     Plot3D[Tanh[(x Sin[Tan[ψ] Log[x^2 + y^2]/2] + y Cos[Tan[ψ] Log[x^2 + y^2]/2])/10],
            {x, -20, 20}, {y, -20, 20}, Axes -> None, BoundaryStyle -> None,
            Boxed -> False, BoxRatios -> Automatic, 
            ColorFunction -> (ColorData["SandyTerrain", Clip[#3 + 1/4, {0, 3/4}]] &),
            Mesh -> False, PlotPoints -> 105, PlotRange -> All]]

I hope it looks somewhat sandy at least.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
4

Any wave form could be used:

ParametricPlot3D[{r Cos[t], r Sin[t], 0.2 TriangleWave[r - t/(2 Pi)]},
 {r, 0, 6}, {t, 0, 2 Pi}, Mesh -> None, PlotPoints -> {121, 30}]

Mathematica graphics

ParametricPlot3D[{r Cos[t], r Sin[t], Sin[r - t]}, {r, 0, 60}, {t, 0, 
  2 Pi}, Mesh -> None, PlotPoints -> {121, 30}]

Mathematica graphics

Etc.

Michael E2
  • 235,386
  • 17
  • 334
  • 747
3
Module[{n = 15, pts},
  pts = Table[{θ Cos[θ], θ Sin[θ], 0}, {θ, 0, n π, π/20}];
  Graphics3D[{GrayLevel[.75], Tube[pts, π]},
    ClipPlanes -> {0, 0, 1, 0},
    Boxed -> False,
    Lighting -> "Neutral"]]

spiral

m_goldberg
  • 107,779
  • 16
  • 103
  • 257