2

I'm using gnuplot to draw a cone with an arrow pointing upwards through the cone's axis of symmetry. The only problem is that I can't figure out how to fit the arrow correctly into the 3D perspective of the picture. By default, the arrow is displayed behind the entire cone. If I add the "front" option to the arrow, it is displayed in front of the entire cone. But, viewed in perspective, the arrow should be in front of the back half of the cone, and behind the front half of the cone.

The obvious solution is to split the function drawing the cone into two halves and make the arrow in front of one curve and behind the other. Is there a way to do that (i.e., manually set the order in which curves and other objects are drawn)? If not, does anyone have a good workaround? (The only one I can think of is to draw the arrow manually using lines, but I'd like to avoid that if possible.)

Here is a minimal working example. I'm using a fine mesh so that the effect is clearly visible.

set arrow 1 from 0,0,0 to 0,0,1 lw 2
set isosamples 100
set xrange [-1:1]
set yrange [-1:1]
set zrange [-1:1]
set zrange [0:1] 
splot sqrt(x**2+y**2) 

To see what's wrong with simply using the "front" option as a fix, replace the first line with:

set arrow 1 from 0,0,0 to 0,0,1 lw 2 front

Thanks in advance for any help!

Edit: I realized after posting that this can be done with multiplot. But it seems like there should be a better solution, so please let me know if you think of one.

sasquires
  • 356
  • 3
  • 15

1 Answers1

2

To hide lines partially, one can usually use set hidden3d, but that does not affect arrows placed with set arrow. However it affects arrows drawn with the vectors plotting style:

set hidden3d
splot sqrt(x**2+y**2), '< echo "0 0 0 0 0 1"' with vectors

But now, one part of the arrow is hidden completely behind the surface and doesn't shine through between the surface lines. For this you can set additionally a second arrow with set arrow back ...:

set isosamples 100
set xrange [-1:1]
set yrange [-1:1]
set zrange [-1:1]
set zrange [0:1]
set hidden3d nooffset
set style arrow 1 lw 2 head filled size 0.1,20,70
unset key
set arrow nohead from 0,0,0 to 0,0,1 as 1 back
splot sqrt(x**2+y**2), '< echo "0 0 0 0 0 1"' with vectors arrowstyle 1

That gives (with 4.6.4):

enter image description here

Christoph
  • 47,569
  • 8
  • 87
  • 187
  • Could you please explain the "echo-part"? – LCsa Nov 20 '16 at 23:06
  • @LCsa That is a way to use some sort of inline data in gnuplot versions before 5.0., the `<` calls a shell, in which the `echo` is executed to send the single line as data to gnuplot. Since 5.0 one can use data blocks, see e.g. http://stackoverflow.com/a/33064653/2604213 – Christoph Nov 21 '16 at 19:54
  • @Christoph thank you! I'll check it out. Then, it seems, I got more confused by what you're actually echoing... the "0 0 0 0 0 1" part... – LCsa Nov 25 '16 at 10:02