I'm working on creating an illustration that I will need in many, different guises in differential geometry/manifold theory etc. Following on from a previous (answered) question of mine (How can I make an arrow from a point in one axis to a point in another?, I want to show how two coordinate lines in the plane originate from two curves on a surface via the chosen map:
\begin{tikzpicture}
\begin{axis}[
name=mfd,
declare function={
f(\x,\y)=10-(\x^2+\y^2);
},
declare function={
c_x(\t)=(cos(\t)+(sin(5*\t)/10))/3+1;
},
declare function={
c_y(\t)=(sin(\t))/2-1;
},
declare function={
c_z(\t)=f(c_x(\t),c_y(\t));
},
]
\addplot3[surf,domain=-2:2,domain y=-2:2,]{f(x,y)};
\addplot3[black,opacity=1.0,variable=t,domain=0:360,dashed,thin] ({c_x(t)},{c_y(t)},{c_z(t)});
\addplot3[black,opacity=1.0,variable=t,domain=-2:2,thin] (t,-1.2,{f(t,-1.2)});
\addplot3[black,opacity=1.0,variable=t,domain=-2:2,thin] (0.8,t,{f(t,-1.2)});
\addplot3[black,opacity=1.0,only marks,mark=text,text mark=$\cdot$] (1,-1,{f(1,-1)}) coordinate (a);
\end{axis}
\begin{axis}[
at={($(mfd.north east)+(1cm,-2cm)$)},
anchor=north west,
declare function={
c_x(\t)=(cos(\t)+(sin(5*\t)/10))/3+1;
},
declare function={
c_y(\t)=(sin(\t))/2-1;
}
]
\addplot[variable=t,domain=0:360]({c_x(t)},{c_y(t)});
\addplot[black,opacity=1.0,only marks,mark=text,text mark=$\cdot$] (1,-1) coordinate (b);
\addplot[variable=t,domain=0.6:1.4](t,-1.2);
\addplot[variable=t,domain=-1.5:-0.5](0.8,t);
\end{axis}
\draw [-stealth, shorten <= 3pt, shorten >= 3pt] (a) to[bend left] (b);
\end{tikzpicture}
However, I have a couple of problems:
- The curves representing the coordinate axes pulled back from the plane via the coordinate map insist on being closed off with a straight line – is there a way to avoid that?
- I want to draw all the black curves with a thin, dashed line, but I probably don't understand how to set those options. What am I doing wrong?
I apologise if these questions are rather elementary, but I find the relevant manuals difficult to search through; they seem to be meant for reading cover to cover rather than reference.
Best Answer
The reason for the problem, I think, can be found in this quote from the
pgfplots
manual:(Emphasis mine.) Note that
samples y=1
will also work, and the manual says this at another point:(Again, emphasis mine. I don't know the technical differences between the two.)
Seems line specifications didn't work for a mesh, and the mesh is also the reason you got closed curves. Hence, if you set
samples y=0
for your black lines, it works as expected. I did that via a style, in the example below.I actually made three different styles, one for the point, one for the coordinate lines, one for the shape, one for the point. You also had the wrong z-coordinate for the second coordinate line, it should be
f(0.8,t)
notf(t,-1.2)
.For the annotations, you can use relative coordinates. Say you have a saved coordinate
c
, you can do something likeThis puts the arrow tip at the start of the path, and the node at the end is placed at
right
of the end of the path. This saves you absolute coordinates, and also having to reuse those in the\node
.I also modified some of the math, notably use
\dim
instead ofdim
, and e.g.$...$ for $...$
instead of$... \ for\ ...$
.