2
$\begingroup$

I'd like to generate microstructures of composite materials and I use an algorithm to find the centers of the spheres knowing also the radius.

My problem is that I only want solid spheres in order to export in a next step this file in .obj type and then in .vtk type.

Does anyone know how to make the spheres solid in the whole sphere's volume?

The plot code I use is the next one:

Graphics3D[{Sphere[X, r]}, PlotRange -> {{0, L}, {0, L}, {0, L}}, Lighting -> Automatic]

where X corresponds to the center of the spheres.

Here is an example of my microstructure:

enter image description here

$\endgroup$
5
  • 3
    $\begingroup$ Ball[X,r] is a solid. $\endgroup$
    – cvgmt
    Dec 14, 2020 at 23:37
  • $\begingroup$ This Compute Lattice Packing Densities:New in Wolfram Language 12 seems relevant. $\endgroup$
    – Tim Laska
    Dec 14, 2020 at 23:42
  • $\begingroup$ @cvgmt Ball gives the same result $\endgroup$ Dec 14, 2020 at 23:43
  • $\begingroup$ @TimLaska Thanks both of you for the quick response, but I forgot to say that I have downloaded the 11.3 version and as I tried the RegionPlot3D command I had the same problem because the spheres looked solid but when I exported in obj type, again looked hollow inside $\endgroup$ Dec 15, 2020 at 0:13
  • $\begingroup$ Could you please let me know how to generate the microstructure you show in the first figure? I am trying to do the same, but I am now still stuck at this problem. Thank you so much. $\endgroup$
    – David
    May 23, 2022 at 8:29

2 Answers 2

2
$\begingroup$

Thanks for @Tim Laska Provide the advice.

centers = RandomReal[{-2, 2}, {10, 3}];
unitball[c_, x_] := EuclideanDistance[c, x] <= 1;
regs = Show[
  RegionPlot3D[
     unitball[#, {x, y, z}], {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, 
     Mesh -> False, Boxed -> False, Axes -> False] & /@ centers]
Export["test.obj",regs]

Or use Ball[] and RegionMember

centers = RandomReal[{-2, 2}, {10, 3}];
Table[RegionPlot3D[
    RegionMember[Ball[center], {x, y, z}], {x, -1, 1}, {y, -1, 
     1}, {z, -1, 1}, Mesh -> False, Boxed -> False, Axes -> False], {center, centers}] // Show;
Export["test.obj", %]

enter image description here

Another way maybe work.

centers = RandomReal[{-2, 2}, {4, 3}];
cuboid = Cuboid[{-1, -1, -1}, {1, 1, 1}];
balls = DiscretizeRegion /@ Ball /@ centers;
newballs = RegionIntersection[#, cuboid] & /@ balls // Quiet;
regs = Show[DeleteCases[newballs, _EmptyRegion]]

enter image description here

$\endgroup$
4
  • $\begingroup$ BoundaryStyle -> None $\endgroup$
    – cvgmt
    Dec 16, 2020 at 23:55
  • $\begingroup$ Thanks a lot for your help! $\endgroup$ Dec 18, 2020 at 19:35
  • $\begingroup$ @CharisSideris Do you have other question about this answer? $\endgroup$
    – cvgmt
    Dec 19, 2020 at 2:04
  • $\begingroup$ No thanks! I solved the problem I had, with your help $\endgroup$ Dec 19, 2020 at 12:40
1
$\begingroup$

Version 13 introduced CSGRegion as an alternative for operations such as RegionDifference. Is that useful for your application?

centers = RandomReal[{-2, 2}, {4, 3}];
cuboid = Cuboid[{-1, -1, -1}, {1, 1, 1}];
balls = Ball /@ centers;
CSGRegion["Intersection", {CSGRegion["Union",balls], cuboid}]

which gives regions like this region

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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