Skip to main content
added 739 characters in body
Source Link
user484
user484

Here's a function to create a random scalar field:

randomFunction3D[xrange_, yrange_, zrange_] := Interpolation[ Flatten[Table[{{x, y, z}, RandomReal[{-1, 1}]}, Evaluate@{x, Sequence @@ xrange}, Evaluate@{y, Sequence @@ yrange}, Evaluate@{z, Sequence @@ zrange}], 2], Method -> "Spline"] 

Now instead of drawing a sphere with constant radius $x^2+y^2+z^2=r^2$, let's make the "radius" vary randomly over space, so we get an irregular blobby shape:

SeedRandom[0]; f = randomFunction3D[{-3, 3}, {-3, 3}, {-3, 3}]; ContourPlot3D[ x^2 + y^2 + z^2 == (1 + 0.4 f[x, y, z])^2, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, Mesh -> None, PlotRange -> All, BoxRatios -> Automatic, Boxed -> False, Axes -> False] 

enter image description hereenter image description here

You can also change the grid spacing to control the size of the bumps:

SeedRandom[0]; f = randomFunction3D[{-3, 3, 0.25}, {-3, 3, 0.25}, {-3, 3, 0.25}]; ContourPlot3D[ x^2 + y^2 + z^2 == (1 + 0.06 f[x, y, z])^2, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, Mesh -> None, PlotRange -> All, BoxRatios -> Automatic, Boxed -> False, Axes -> False] 

enter image description here

You can have a lot of fun adding a bunch of different random fields with different scalings to create interesting effects, but I'll leave that as an exercise. For inspiration, see Ken Perlin's classic Making Noise talk.

Here's a function to create a random scalar field:

randomFunction3D[xrange_, yrange_, zrange_] := Interpolation[ Flatten[Table[{{x, y, z}, RandomReal[{-1, 1}]}, Evaluate@{x, Sequence @@ xrange}, Evaluate@{y, Sequence @@ yrange}, Evaluate@{z, Sequence @@ zrange}], 2], Method -> "Spline"] 

Now instead of drawing a sphere with constant radius $x^2+y^2+z^2=r^2$, let's make the "radius" vary randomly over space, so we get an irregular blobby shape:

SeedRandom[0]; f = randomFunction3D[{-3, 3}, {-3, 3}, {-3, 3}]; ContourPlot3D[ x^2 + y^2 + z^2 == (1 + 0.4 f[x, y, z])^2, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, Mesh -> None, PlotRange -> All, BoxRatios -> Automatic, Boxed -> False, Axes -> False] 

enter image description here

Here's a function to create a random scalar field:

randomFunction3D[xrange_, yrange_, zrange_] := Interpolation[ Flatten[Table[{{x, y, z}, RandomReal[{-1, 1}]}, Evaluate@{x, Sequence @@ xrange}, Evaluate@{y, Sequence @@ yrange}, Evaluate@{z, Sequence @@ zrange}], 2], Method -> "Spline"] 

Now instead of drawing a sphere with constant radius $x^2+y^2+z^2=r^2$, let's make the "radius" vary randomly over space, so we get an irregular blobby shape:

SeedRandom[0]; f = randomFunction3D[{-3, 3}, {-3, 3}, {-3, 3}]; ContourPlot3D[ x^2 + y^2 + z^2 == (1 + 0.4 f[x, y, z])^2, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, Mesh -> None, PlotRange -> All, BoxRatios -> Automatic, Boxed -> False, Axes -> False] 

enter image description here

You can also change the grid spacing to control the size of the bumps:

SeedRandom[0]; f = randomFunction3D[{-3, 3, 0.25}, {-3, 3, 0.25}, {-3, 3, 0.25}]; ContourPlot3D[ x^2 + y^2 + z^2 == (1 + 0.06 f[x, y, z])^2, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, Mesh -> None, PlotRange -> All, BoxRatios -> Automatic, Boxed -> False, Axes -> False] 

enter image description here

You can have a lot of fun adding a bunch of different random fields with different scalings to create interesting effects, but I'll leave that as an exercise. For inspiration, see Ken Perlin's classic Making Noise talk.

Source Link
user484
user484

Here's a function to create a random scalar field:

randomFunction3D[xrange_, yrange_, zrange_] := Interpolation[ Flatten[Table[{{x, y, z}, RandomReal[{-1, 1}]}, Evaluate@{x, Sequence @@ xrange}, Evaluate@{y, Sequence @@ yrange}, Evaluate@{z, Sequence @@ zrange}], 2], Method -> "Spline"] 

Now instead of drawing a sphere with constant radius $x^2+y^2+z^2=r^2$, let's make the "radius" vary randomly over space, so we get an irregular blobby shape:

SeedRandom[0]; f = randomFunction3D[{-3, 3}, {-3, 3}, {-3, 3}]; ContourPlot3D[ x^2 + y^2 + z^2 == (1 + 0.4 f[x, y, z])^2, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, Mesh -> None, PlotRange -> All, BoxRatios -> Automatic, Boxed -> False, Axes -> False] 

enter image description here