# Slice through Graphics3D

is there any possibility to slice through a Graphics3D object? At the end I would like to have a stack of images slicing , e.g. $n$ times in $z$-direction: $((x,y,z_{0}), (x,y,z_{1}),…,(x,y,z_{n}))$

Here is an example of random spheres, which I would like to slice.

z = 100;
p = RandomReal[100, {z, 3}];
r = RandomReal[10, {z}];
obj = GraphicsComplex[p, Sphere[Range[z], r]];
t0 = AbsoluteTime[];
gr = Graphics3D[obj, Axes -> True]


• You can use PlotRange to emulate that to a certain degree, try: Manipulate[ gr = Graphics3D[obj, Axes -> True, PlotRange -> {Automatic, Automatic, {0, z}}], {{z, 100}, 0, 100}]. For the image stack, this will be more complicated... Commented Sep 25, 2013 at 6:56
• If you only want circle sections, this could be solved in an analytic fashion. Intersections on general graphics objects are not implemented yet (9.01). Commented Sep 25, 2013 at 7:31
• It seems that @YvesKlett is right so maybe you can confirm that your objects are only Spheres or provide a minimal example of the data you are working with so we can help with your case.
– Kuba
Commented Sep 25, 2013 at 8:37
• Commented Sep 25, 2013 at 14:36

You can do this by specifying a dynamic PlotRange. Here is an example using Manipulate. You will need to adapt your range for each dimension:

z = 100;
p = RandomReal[100, {z, 3}];
r = RandomReal[10, {z}];
obj = GraphicsComplex[p, Sphere[Range[z], r]];
t0 = AbsoluteTime[];
gr = Graphics3D[obj, Axes -> True]

Manipulate[
Show[gr, PlotRange -> {{x, Automatic}, {y, Automatic}, {z,
Automatic}}], {x, 0, 100, 1}, {y, 0, 100, 1}, {z, 0, 100, 1}]


In order to generate images you will have to replace the Manipulate by a Table command and generate the images. Have a closer look at ViewPoint to specify the view on your Graphics3D object. This will allow you to generate images looking from the different directions.

Here is an example:

Manipulate[
Show[gr, ViewPoint -> {0, -Infinity, 0},
PlotRange -> {{x, Automatic}, {y, Automatic}, {z, Automatic}}], {x,
0, 100, 1}, {y, 0, 100, 1}, {z, 0, 100, 1}]


edit

To get sections you could also use PlotRange. Here is an example giving you slices of thickness 1 in y-direction:

Manipulate[
Show[gr, ViewPoint -> {0, -Infinity, 0},
PlotRange -> {{x, Automatic}, {y, y + 1}, {z, Automatic}}], {x, 0,
100, 1}, {y, 0, 100, 1}, {z, 0, 100, 1}]


If you have the analytical expressions for your surfaces (as it's the case for the spheres) there are lot of ways to do that by using any *3D[] plotting function like this:

Image3D@Table[ImageTake[
Image@Plot3D[Sin[x y], {x, -3, 3}, {y, -3, 3},
PlotRange -> {-1, s}, ClippingStyle -> {Transparent, Green},
Boxed -> False, Axes -> False, PlotStyle -> Transparent,
Mesh -> None, ViewPoint -> {0, 0, -Infinity}],
10 {1, -1}, 10 {1, -1}],
{s, -.9, .7, .1}]


• yuck... why green? Image search returns this :-) Commented Sep 25, 2013 at 14:43
• @YvesKlett Green, as most things in the history of mathematics is just because I like it en.wikipedia.org/wiki/History_of_mathematical_notation :) Commented Sep 25, 2013 at 15:05