3
$\begingroup$

I think there should be an easy way to accomplish my task but I have not found it yet. I would like Graphics3D to plot a simple sphere, radius $1$, centered on ${0,0,0}$. And, the plot should be without a box (easy to do) but with coordinate axis that are centered on the sphere itself. With Graphics3D those coordinate axis are outside of the sphere as if they were labeling 3 edges of the bounding box.

The surface of the sphere should be viewed as somewhat transparent where the axis inside the sphere can be viewed.

I would like guidance on how to go about this, thinking it must be a common need there must be a simple parameter that I have not yet found. I am sure that I could construct such a 3D image manually by drawing each axis but I am hoping to avoid that.

I admit to being an novice with Mathematica graphics and especially Graphics3D.

$\endgroup$
  • 3
    $\begingroup$ us e AxesOrigin -> {0, 0, 0}? $\endgroup$ – kglr Jun 24 '18 at 19:47
  • 2
    $\begingroup$ And Boxed -> False? And Opacity[0.5] for the sphere? $\endgroup$ – Henrik Schumacher Jun 24 '18 at 20:06
  • $\begingroup$ You missed Axes -> True ! $\endgroup$ – rhermans Jun 24 '18 at 21:09
  • 1
    $\begingroup$ @K7PEH next time, instead of saying "easy to do", please show us the code you have, so we can know how far you have done yourself. The question itself, if you share what you have learned, could be good help for other users visiting the site. $\endgroup$ – rhermans Jun 24 '18 at 21:13
  • 1
    $\begingroup$ @rhermans -- Actually, your answer was exactly the sort of thing I was looking for and in fact assumed to exist in Mathematica but I just didn't see it in my reading of the docs (as I explained above). If you re-read my question, you see that I mention "easy" and that "...there must be a parameter [to do this]". And, you showed me that very parameter, the very one I assume should exist, the very one I in fact did use already from your info. It fit my need. This is why I accepted your answer. Jens answer is interesting and probably useful but his extra work was what I wanted to avoid. $\endgroup$ – K7PEH Jun 25 '18 at 14:51
4
$\begingroup$

The Graphics3D

Graphics3D[
 {Opacity[0.5], Sphere[{0, 0, 0}]}
 , AxesOrigin -> {0, 0, 0}
 , Boxed -> False
 , Axes -> True
 , PlotRange -> {{-2, 2}, {-2, 2}, {-2, 2}}
 ]

Mathematica graphics

How to go about this.

A good starting point is to look at the documentation about Graphics3D, search this site, and look at the Options of the relevant functions.

Options[Graphics3D]
(* {AlignmentPoint -> Center, AspectRatio -> Automatic, 
 AutomaticImageSize -> False, Axes -> False, AxesEdge -> Automatic, 
 AxesLabel -> None, AxesOrigin -> Automatic, AxesStyle -> {}, 
 Background -> None, BaselinePosition -> Automatic, BaseStyle -> {}, 
 Boxed -> True, BoxRatios -> Automatic, BoxStyle -> {}, 
 ClipPlanes -> None, ClipPlanesStyle -> Automatic, 
 ColorOutput -> Automatic, ContentSelectable -> Automatic, 
 ControllerLinking -> Automatic, ControllerMethod -> Automatic, 
 ControllerPath -> Automatic, CoordinatesToolOptions -> Automatic, 
 DisplayFunction :> $DisplayFunction, Epilog -> {}, FaceGrids -> None,
  FaceGridsStyle -> {}, FormatType :> TraditionalForm, 
 ImageMargins -> 0., ImagePadding -> All, ImageSize -> Automatic, 
 ImageSizeRaw -> Automatic, LabelStyle -> {}, Lighting -> Automatic, 
 Method -> Automatic, PlotLabel -> None, PlotRange -> All, 
 PlotRangePadding -> Automatic, PlotRegion -> Automatic, 
 PreserveImageOptions -> Automatic, Prolog -> {}, 
 RotationAction -> "Fit", SphericalRegion -> False, 
 Ticks -> Automatic, TicksStyle -> {}, TouchscreenAutoZoom -> False, 
 ViewAngle -> Automatic, ViewCenter -> Automatic, 
 ViewMatrix -> Automatic, ViewPoint -> {1.3, -2.4, 2.}, 
 ViewProjection -> Automatic, ViewRange -> All, 
 ViewVector -> Automatic, ViewVertical -> {0, 0, 1}} *)
$\endgroup$
5
$\begingroup$

Even though an answer was already accepted, let me post how I like to make axes in 3D:

First, define a general 3D arrow, called arrowLine (it allows a more robust way of specifying the proportions of the shape, compared to the built-in Arrow command). See this answer. Then I combine three such arrows in the function arrowAxes to make a coordinate system:

Options[arrowLine] = {Thickness -> .1, "HeadScale" -> 3};
arrowLine[{p1_, p2_}, 
  OptionsPattern[]] :=
(*p1 and p2 are 3D points. They are passed as a list*)
 Module[{p3, scale2, norm, pyramidHeight = 3/2}, 
  scale2 = OptionValue["HeadScale"]*OptionValue[Thickness];
  norm = Norm[p2 - p1];
  If[norm > scale2*pyramidHeight, 
   p3 = p1 + (p2 - p1)/norm (norm - scale2 pyramidHeight);
   {EdgeForm[], Cylinder[{p1, p3}, OptionValue[Thickness]], 
    GeometricTransformation[
     GraphicsComplex[{{0, 0, pyramidHeight}, {0, -1, 0}, {0, 1, 
        0}, {-1, 0, 0}, {1, 0, 0}}, 
      Polygon[{{3, 4, 1}, {4, 2, 1}, {2, 5, 1}, {5, 3, 1}, {5, 2, 4, 
         3}}]], Composition[TranslationTransform[p3], 
      Quiet[RotationTransform[{{0, 0, 1}, 
         p2 - p1}], {RotationMatrix::degen, RotationTransform::spln}],
       ScalingTransform[scale2 {1, 1, 1}]]]}, {}]]   

arrowAxes[forwardLength_, backwardLength_: 0] := 
 Map[{Apply[RGBColor, #], 
    arrowLine[{-backwardLength #, forwardLength #}, 
     Thickness -> .05]} &, IdentityMatrix[3]]

Now the 3D axes can be combined with a partially translucent sphere as follows:

Graphics3D[{{Opacity[.7], Orange, Sphere[]}, arrowAxes[3, 3]}, 
 Boxed -> False, Lighting -> "Neutral", Background -> Gray]

Mathematica graphics

The translucent effect is created by Opacity and the axes are drawn by arrowAxes[3, 3]. Here, the first argument is the length of the arrows in the forward direction from the origin, and the second argument is the length in the reverse direction. You can omit the second argument to get axes that only extend in the forward direction (bordering the first octant).

$\endgroup$
  • $\begingroup$ Thanks for the effort in your answer. I have copied your arrowAxes code to save for some other use I might have in the future. However, I do have to say that the AxesOrigin option parameter is exactly what I was looking for and hoping to find for my current need. But, I am already thinking of ways to use your code and more importantly to learn more skills in writing such things in Mathematica. $\endgroup$ – K7PEH Jun 25 '18 at 15:04

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.