When I create a Graphics3D
, I often want to place an object right at the centre of the box. Initially I thought that the centre was specified by {0, 0, 0}
, but I soon realised that this is actually the corner.
I've realised that I can find the centre by dividing the dimensions of the box in half. For example if
PlotRange -> {{0, 100}, {0, 100}, {0, 100}}
then if I want to put my Sphere
dead centre I'll put it at:
Sphere[{100/2, 100/2, 100/2, 1]
This is all very well if I explicitly know the dimensions of the box, but if I don't know the PlotRange
, how can I ensure that my object is placed right at the centre?
Is there a way to tell the size of the PlotRange
if you haven't specified it explicitly?
For example, consider this function:
balls = Table[Sphere[RandomReal[{0, 100}, 3], 1], {50}]~
Join~{Sphere[{50, 50, 50}, .05]};
Manipulate[
Graphics3D[
balls,
ViewPoint -> {1.3*10^-zoom, -2.4*10^-zoom, 2*10^-zoom},
SphericalRegion -> True,
PlotRange -> {{0, 100}, {0, 100}, {0, 100}}],
{zoom, 0, 3}]
The slider controls the zoom, which in this function zooms in all the way until you hit a very small sphere. For this to work though, the sphere needs to be precisely at the centre of the plot. To ensure this precision, I manually entered the size of the plot (PlotRange -> {{0, 100}, {0, 100}, {0, 100}}
), as well as manually control the placement of the middle sphere (Sphere[{50, 50, 50}, .05]
).
Is there a way to make sure that this sphere is placed right at the very centre of the box without needing to manually specify either the dimensions of the PlotRange
or the coordinates of the centre sphere?
I hope this clarifies what I'm trying to get at.
ViewCenter->{0.5,0.5,0.5}
might be what you are after. $\endgroup${BoxSize/2, BoxSize/2, BoxSize/2}
. Alternatively I don't really mind specifying the coordinates of theSphere
, but in order to do that I need to know what the dimensions of the box are. Is there a way to discover what these are without my specifying what they are? I.e. I just want to let Mma decide what size the box should be, but then I want to find out what it is so that I can specify that I want the sphere to be placed at half the width, height and depth $\endgroup$