I am utilizing some code for a 2D observing eye and trying to position it within a 3D Cartesian coordinate system. However, when I execute the code below, the 2D eye is positioned well outside the specified axes and it is unclear as to what coordinate system it is being oriented with respect to. How can I control the position of the 2D structure while leaving its definition intact?
\documentclass[border=4pt]{standalone}
\usepackage{pgfplots}
\usepackage{tikz-3dplot}
\usepgfplotslibrary{colormaps,external}
\usetikzlibrary{calc,3d,arrows,shapes.geometric}
\pgfplotsset{compat=1.9,colormap={whitered}{color(0cm)=(yellow);
color(1cm)=(orange!75!red)},colormap={bidom}{color(0cm)=(white);
color(1cm)=(blue!75!red)}}
\begin{document}
\tdplotsetmaincoords{60}{150}%
\begin{tikzpicture}[tdplot_main_coords]
\begin{axis}[
axis equal,
axis lines = center,
width = 8cm,
height = 8cm,
view/h=25,
axis lines=none
]
\newcommand{\eye}[4]% size, x, y, rotation
{ \draw[rotate around={#4:(#2,#3)}] (#2,#3) -- ++(-.5*55:#1) (#2,#3) --
++(.5*55:#1);
\draw (#2,#3) ++(#4+55:.75*#1) arc (#4+55:#4-55:.75*#1);
% IRIS
\draw[fill=gray] (#2,#3) ++(#4+55/3:.75*#1) arc
(#4+180-55:#4+180+55:.28*#1);
%PUPIL, a filled arc
\draw[fill=black] (#2,#3) ++(#4+55/3:.75*#1) arc (#4+55/3:#4-55/3:.75*#1);
}
\addplot3[surf, opacity = 0.5,
samples=30,
domain=-15:15,
y domain=0:pi,
z buffer=sort,color=gray!50!black]
({sqrt(15*15-x^2) * cos(deg(y))},
{sqrt( 15*15-x^2 ) * sin(deg(y))},
x);
\addplot3[surf, opacity = 0.5,
samples=31,
domain=-15:15,
y domain=pi/2:3*pi/2,
z buffer=sort,color=gray!50!black]
({sqrt(15*15-x^2) * cos(deg(y))},
{sqrt( 15*15-x^2 ) * sin(deg(y))},
x);
\addplot3[surf, opacity = 0.5,
samples=16,
domain=-15:0,
y domain=0:-pi/2,
z buffer=sort,color=gray!50!black]
({sqrt(15*15-x^2) * cos(deg(y))},
{sqrt( 15*15-x^2 ) * sin(deg(y))},
x);
\addplot3[surf, opacity = 0.5,
samples=21,domain=0:15.0,
y domain=0:0.5*pi,z buffer=sort]
({sqrt( 15*15-x^2 ) * sin(deg(y))}, 0, x);
\addplot3[surf, opacity = 0.5,
samples=21,domain=0:15.0,
y domain=-0.5*pi:0,z buffer=sort]
(0, {sqrt( 15*15-x^2 ) * sin(deg(y))}, x);
\addplot3[surf, opacity = 0.5,
samples=21,domain=0:15.0,
y domain=-0.5*pi:0,z buffer=sort]
(x, {sqrt( 15*15-x^2 ) * sin(deg(y))}, 0);
\addplot3 [domain = 0.0:15.0, samples = 50, samples y = 0, thick,
smooth,color=blue]
(x,0,{x^3*exp(-x/1.5)});
\addplot3 [domain = 0.066:15.0, samples = 50, samples y = 0, thick,
smooth,color=red]
(x,0,{1/(x)});
\addplot3[surf,opacity=0.1,domain=0.05:15.0,y domain=-
10.0:0.0,samples=50]
({x*cos(y)}, {x*sin(y)}, {x^3*exp(-x/1.5)});
\draw [->,black] (axis cs:0,0,0) -- (axis cs:20,0,0);
\draw [->,black] (axis cs:0,0,0) -- (axis cs:0,0,20);
\draw [->,black] (axis cs:0,0,0) -- (axis cs:0,-20,0);
\begin{scope}[canvas is xz plane at y=0]
\eye{16}{8}{8}{45}
\end{scope}
\end{axis}
\end{tikzpicture}
\end{document}
lightweight code
\documentclass[border=4pt]{standalone}
\usepackage{pgfplots}
\usepackage{tikz-3dplot}
\usepgfplotslibrary{colormaps,external}
\usetikzlibrary{calc,3d,arrows,shapes.geometric}
\pgfplotsset{
compat=1.9,
colormap={whitered}{color(0cm)=(yellow);color(1cm)=(orange!75!red)},
colormap={bidom}{color(0cm)=(white);color(1cm)=(blue!75!red)}
}
\begin{document}
\tdplotsetmaincoords{60}{150}%
\begin{tikzpicture}[tdplot_main_coords]
\begin{axis}[axis equal,axis lines=center,width = 8cm,height = 8cm,view/h=25,axis lines=none]
\newcommand{\eye}[4]% size, x, y, rotation
{
\draw[rotate around={#4:(#2,#3)}](#2,#3)--++(-.5*55:#1)(#2,#3)--++(.5*55:#1);
\draw(#2,#3)++(#4+55:.75*#1)arc(#4+55:#4-55:.75*#1);
% IRIS
\draw[fill=gray](#2,#3)++(#4+55/3:.75*#1)arc(#4+180-55:#4+180+55:.28*#1);
%PUPIL, a filled arc
\draw[fill=black](#2,#3)++(#4+55/3:.75*#1)arc(#4+55/3:#4-55/3:.75*#1);
}
\addplot3[surf,opacity=.5,samples=10,domain=-15:15,y domain=0:pi,z buffer=sort,color=gray!50!black]
({sqrt(15*15-x^2)*cos(deg(y))},{sqrt(15*15-x^2)*sin(deg(y))},x);
\addplot3[surf,opacity=.5,samples=9,domain=-15:15,y domain=pi/2:3*pi/2,z buffer=sort,color=gray!50!black]
({sqrt(15*15-x^2)*cos(deg(y))},{sqrt(15*15-x^2)*sin(deg(y))},x);
\addplot3[surf,opacity=.5,samples=9,domain=-15:0,y domain=0:-pi/2,z buffer=sort,color=gray!50!black]
({sqrt(15*15-x^2)*cos(deg(y))},{sqrt(15*15-x^2)*sin(deg(y))},x);
\addplot3[surf,opacity=.5,samples=9,domain=0:15,y domain=0:.5*pi,z buffer=sort]({sqrt(15*15-x^2)*sin(deg(y))},0,x);
\addplot3[surf,opacity=.5,samples=9,domain=0:15,y domain=-.5*pi:0,z buffer=sort](0,{sqrt(15*15-x^2)*sin(deg(y))},x);
\addplot3[surf,opacity=.5,samples=9,domain=0:15,y domain=-.5*pi:0,z buffer=sort](x,{sqrt(15*15-x^2)*sin(deg(y))},0);
\addplot3[domain=0:15,samples=9,samples y=0,thick,smooth,color=blue](x,0,{x^3*exp(-x/1.5)});
\addplot3[domain=.066:15,samples=9,samples y=0,thick,smooth,color=red](x,0,{1/(x)});
\addplot3[surf,opacity=.1,domain=.05:15,y domain=-10:0,samples=9]({x*cos(y)},{x*sin(y)},{x^3*exp(-x/1.5)});
\draw[->,black](axis cs:0,0,0)--(axis cs:20,0,0)node{x};
\draw[->,black](axis cs:0,0,0)--(axis cs:0,0,20);
\draw[->,black](axis cs:0,0,0)--(axis cs:0,-20,0);
\begin{scope}[canvas is xz plane at y=0]
\eye{16}{8}{8}{45}
\end{scope}
\end{axis}
\end{tikzpicture}
\end{document}
rotate around
is a 2D option andcanvas is xz plane at y
is a 3D option. Mixing them does not make perfect sense. What exactly do you want?rotate around
--- this option does not recognize the 3D information and will mess things up. I recently found a way to achieve true 3D rotation. But it might be overkill.