4
$\begingroup$

I have a sphere that I am placing in a graph that has uneven dimensions and as a result it looks like a flattened disk. I imagine that some scaling command might allow me to show it properly. I offer an example code. My real code has many spheres being placed in a range from {2,139,0} to {4,170,1}. The coordinates of the spheres are in the coordinates of that space, therefore I do not want to scale the coordinates, I only want to scale the radius. Unless an easy way exists to inverse scale the coordinates.

Graphics3D[{
  Polygon[{
    {0, 0, 0},
    {1, 0, 0},
    {0, 10, 0}}],
  Sphere[{.5, 5, .5}, .4]
  },
 Axes -> True,
 BoxRatios -> {1, 1, 1}]
$\endgroup$
  • 1
    $\begingroup$ You could use Ellipsoid instead of sphere. Then you'd probably want to extract the aspect ratio of the plot (or set it by hand) and use appropriate semi-axes. $\endgroup$ – N.J.Evans Nov 3 '16 at 17:50
  • 1
    $\begingroup$ Graphics3D[{ Polygon[{{0, 0, 0}, {1, 0, 0}, {0, 10, 0}}], Sphere[{.5, 5, .5}, .4]}, Axes -> True, PlotRange -> {{0, 1}, {0, 10}, {0, 1}}, BoxRatios -> {1, 10, 1}] $\endgroup$ – Bob Hanlon Nov 3 '16 at 17:50
3
$\begingroup$
plotrange = {{a, b}, {c, d}, {e, f}} = {{0, 1}, {0, 10}, {0, 1}};
r = 0.4;
Graphics3D[{Polygon[{{0, 0, 0}, {1, 0, 0}, {0, 10, 0}}], 
  Ellipsoid[{.5, 5, .5}, {b - a, d - c, f - e} r]}, Axes -> True, 
 PlotRange -> plotrange, BoxRatios -> {1, 1, 1}]

enter image description here


The same works for a number of spheres/ellipsoids:

plotrange = {{a, b}, {c, d}, {e, f}} = {{2, 4}, {139, 170}, {0, 1}};
n = 10; (* number of spheres *)
r = RandomReal[0.2, n]; (* radii of the spheres *)
pts = Table[{RandomReal[{a, b}], RandomReal[{c, d}], RandomReal[{e, f}]}, {i, 1, n}];
    (* centers of the spheres *)
ellipsoids = Table[Ellipsoid[pts[[i]], {b - a, d - c, f - e} r[[i]]], {i, 1, n}]; 
           (*suitably scaled spheres/ellipsoids *)

Graphics3D[
 Join[{Polygon[{{2, 139, 0}, {4, 139, 0}, {2, 170, 0}}]}, ellipsoids],
  Axes -> True, PlotRange -> plotrange, BoxRatios -> {1, 1, 1}]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Nice, Corey! Many thanks. $\endgroup$ – Nicholas G Nov 3 '16 at 22:02

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.