TransWikia.com

Show Graphics on top of ParametricPlot3D

Mathematica Asked on November 25, 2021

I want to show a curved trajectory in 3D with a small Sphere/Point denoting a specific point. Therefore, the Sphere/Point needs to be always visualised "in front" of the curve; instead, I get exactly the opposite, even though I Show the sphere afterwards:

Show[ParametricPlot3D[{0, Cos[4 t], Sin[4 t]}, {t, 0, 2}],
 Graphics3D[{Red, PointSize[0.02], Opacity[1], Point[{0, 1, 0}]}, 
  Boxed -> False],
 Boxed -> False, Axes -> False, PlotRange -> Full]

Setting max opacity didn’t help, as you can see.


Update: Using Ball does not solve the problem in all orientations:

Show[ParametricPlot3D[{0, Cos[4 t], Sin[4 t]}, {t, 0, 2}], 
 Graphics3D[{Red, Ball[{0, 1, 0}, 0.05]}, Boxed -> False], 
 Boxed -> False, Axes -> False, PlotRange -> Full,
 ViewAngle -> 0.05441036690859109`, 
 ViewCenter -> {{0.5`, 0.5`, 
    0.5`}, {-0.4060312376176072`, -0.06631185777677895`}}, 
 ViewPoint -> {1.2849282470004935`, -2.9518747023382326`, 
   1.0418229896464233`}, 
 ViewVertical -> {0.8518775666674835`, -0.15812469380775868`, 
   0.49930070360143686`}]

The inaccurate intersection is shown simply by using the ViewPoint setting, but I zoomed in to highlight the problem.

One Answer

You mean you want even the part of the point/ball that is behind the curve to be drawn in front? The normal 3D model won't do that, I'm pretty sure. You could have layers, such as you get with Overlay, but you have to take care that all the visualization parameters agree (ViewPoint, PlotRange, ImageSize, etc.):

Overlay[{
  ParametricPlot3D[{0, Cos[4 t], Sin[4 t]}, {t, 0, 2},
   Boxed -> False, Axes -> False, PlotRange -> 1], 
  Graphics3D[{Red, Ball[{0, 1, 0}, 0.05]}, Boxed -> False,
   Boxed -> False, Axes -> False, PlotRange -> 1]
  }]

Note that the output is not a Graphics3DBox[..] and cannot be rotated.

I feel that the OP's version of @MarcoB's suggestion is the best way, in which the curve passes through the ball in a natural way:

Show[
 ParametricPlot3D[{0, Cos[4 t], Sin[4 t]}, {t, 0, 2}], 
 Graphics3D[{Red, Ball[{0, 1, 0}, 0.05]}, Boxed -> False], 
 Boxed -> False, Axes -> False, PlotRange -> Full]

I think I understand the comment: The intersection of the Line and the Ball is not shown accurately from all view points.

Things seem to be displayed more accurately if the graphics elements all have the same dimension. If we use surface elements for both the line and point, namely Tube and Ball, the displayed graphics perhaps look better.

Show[ParametricPlot3D[{0, Cos[4 t], Sin[4 t]}, {t, 0, 2}, 
  PlotStyle -> Tube[0.01]], 
 Graphics3D[{Red, Ball[{0, 1, 0}, 0.05]}, Boxed -> False], 
 Boxed -> False, Axes -> False, PlotRange -> Full]

Answered by Michael E2 on November 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP