# Discretize a Graphics3D object over a given 3D lattice

Is there a way to discretize a Graphics3D object using a regular lattice with a given lattice spacing. For example:

Graphics3D[Sphere, PlotRange -> {{-5, 5}, {-5, 5}, {-5, 5}}]


or in the case of multiple spheres:

ClearAll["Global*"]
array1 = {1, 5, -2};
array2 = {2, 6, -1};
array3 = {3, 3, 2};
array4 = {1, 3, 2};
Ball[{#1, #2, #3}, #4] &, {array1, array2, array3, array4}];
Graphics3D[{Red, ONE}, ImageSize -> 400, ImageSize -> 600,
PlotRange -> {{-10, 10}, {-10, 10}, {-10, 10}}, ImageSize -> 400,
Axes -> True,
LabelStyle -> {FontFamily -> "Arial", FontSize -> 20}];


I'd like 1s for lattice points lying in the sphere region and 0s for everything outside. For a lattice spacing of 1, I would expect 11*11*11 points.

• Will DiskMatrix[All, {11, 11, 11}] work for you? May 27, 2017 at 13:48
• How would that work if i have multiple spheres in a box? I want to be able to imposed box size, center of spheres and radii of them. May 27, 2017 at 14:05
• Are your multiple spheres intersecting or not? May 27, 2017 at 17:41
• If your question is really about multiple spheres in a box, please edit your question to reflect this. The example you current give is too simple to adequately frame your question. May 28, 2017 at 8:25
• Ok, edited my question to reflect that. May 30, 2017 at 14:44

I will answer your question using a more complex example based on two intersecting balls (solids -- spheres are surfaces).

Graphics3D[{Ball[{-2, 0, 0}, 3], Ball[{2, 0, 0}, 3]}, Boxed -> False] 3D region formed by the two balls.

 r = RegionUnion[{Ball[{-2, 0, 0}, 3], Ball[{2, 0, 0}, 3]}];


Regular lattice over the cube with corners at {{-5, -5, -5}, {5, 5, 5}} with lattice points separated by 0.25 in direction. (I want more points than a 11 x 11 x 11 lattice would give).

mesh = CoordinateBoundingBoxArray[{{-5, -5, -5}, {5, 5, 5}}, .25];
Dimensions @ mesh


{41, 41, 41, 3}

Selecting the points that lie within the region r.

pts = Select[Flatten[mesh, 2], RegionMember[r, #] &];
ListPointPlot3D[pts,
PlotRange -> {{-5, 5}, {-5, 5}, {-5, 5}},
BoxRatios -> {1, 1, 1},
ImageSize -> Medium] Now let's build a boolean array with a 1 at each point of r that falls on the lattice.

sa = SparseArray @ Map[Boole[RegionMember[r, #]] &, mesh, {-2}]
` • Thank you all for your responses. m_goldberg's solution is exactly what i was looking for. May 30, 2017 at 14:43