1

I would like to ask,how can we draw 50 spheres of radius 0.1 (randomly) in the unit cube.

This is my first try,

Graphics3D[
 Table[{Red, Sphere[RandomReal[{0.1, 0.9}, 3], 0.1]}, {50}], 
 PlotRange -> {0, 1}]

To define a unit cube is this enough???

ABCDEMMM
  • 1,816
  • 1
  • 9
  • 17

1 Answers1

2

Your approach is fine.

A few alternatives you might consider:

  1. You can generate random centers using a single call to RandomReal:

Graphics3D[{Red, Sphere[RandomReal[{0.1, 0.9}, {50, 3}], 0.1]}, 
 PlotRange -> {0, 1}]

enter image description here

  1. You can transform Cuboid[] and use it with RandomPoint as follows:

r = .1;

transformedCuboid = Cuboid[r {1, 1, 1}, (1 - r) {1, 1, 1}];

centers = RandomPoint[transformedCuboid, 30];

Graphics3D[{PointSize[Medium], Point@centers, Opacity[.5, Red], Sphere[#, r] & /@ centers, EdgeForm[Blue], FaceForm[], Cuboid[], EdgeForm[Green], transformedCuboid}]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896