0
$\begingroup$

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

Graphics3D[Sphere[3], 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};
ONE = MapThread[
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.

$\endgroup$
5
  • $\begingroup$ Will DiskMatrix[All, {11, 11, 11}] work for you? $\endgroup$
    – Shadowray
    May 27, 2017 at 13:48
  • $\begingroup$ 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. $\endgroup$
    – user147813
    May 27, 2017 at 14:05
  • $\begingroup$ Are your multiple spheres intersecting or not? $\endgroup$ May 27, 2017 at 17:41
  • $\begingroup$ 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. $\endgroup$
    – m_goldberg
    May 28, 2017 at 8:25
  • $\begingroup$ Ok, edited my question to reflect that. $\endgroup$
    – user147813
    May 30, 2017 at 14:44

1 Answer 1

1
$\begingroup$

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]

balls

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]

pt_plot

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}]

boolean_array

$\endgroup$
1
  • $\begingroup$ Thank you all for your responses. m_goldberg's solution is exactly what i was looking for. $\endgroup$
    – user147813
    May 30, 2017 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.