4

I'm trying to graph the tangent plane on the unit sphere at the point (1, \pi/3,\pi/4). I'm new to tikz, so I'm unsure how to edit the graphs other users have made with the planes for each point. Here's the current graph of a sphere I have:

\begin{tikzpicture}
    \begin{axis}[%
        axis equal,
        width=10cm,
        height=10cm,
        axis lines = center,
        xlabel = {$x$},
        ylabel = {$y$},
        zlabel = {$z$},
        ticks=none,
        enlargelimits=0.3,
        view/h=45,
        scale uniformly strategy=units only,
    ]
    \addplot3[%
        opacity = 0.5,
        surf,
        z buffer = sort,
        samples = 21,
        variable = \u,
        variable y = \v,
        domain = 0:180,
        y domain = 0:360,
    ]
    ({cos(u)*sin(v)}, {sin(u)*sin(v)}, {cos(v)});
    \end{axis}
\end{tikzpicture}

What's the easiest way to add the tangent plane to the graph? Do I have to create 4 nodes and then fill the rectangle they make? Or is it possible to create a plane based on the span of two vectors originating from that point? Any and all help/explanations would be greatly appreciated!

8

This is a style that inserts a plane at a point that is spanned by two vectors.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[tangent plane/.style args={at #1 with vectors #2 and #3}{%
insert path={#1 --  ($#1+($#2-(0,0,0)$)$) --  ($#1+($#2-(0,0,0)$)+($#3-(0,0,0)$)$) 
-- ($#1+($#3-(0,0,0)$)$) -- cycle}}]
    \begin{axis}[%
        axis equal,
        width=10cm,
        height=10cm,
        axis lines = center,
        xlabel = {$x$},
        ylabel = {$y$},
        zlabel = {$z$},
        ticks=none,
        enlargelimits=0.3,
        view/h=45,
        scale uniformly strategy=units only,
    ]
    \addplot3[%
        opacity = 0.5,
        surf,
        z buffer = sort,
        samples = 21,
        variable = \u,
        variable y = \v,
        domain = 0:180,
        y domain = 0:360,
    ]
    ({cos(u)*sin(v)}, {sin(u)*sin(v)}, {cos(v)});
    \draw[fill=white,fill opacity=0.4,
    tangent plane=at {(-0.5,-0.5,1)} with vectors {(1,0,0)} and {(0,1,0)}];
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

The mandatory animation:

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{calc}
\begin{document}
\tikzset{tangent plane/.style args={at #1 with vectors #2 and #3}{%
    insert path={#1 --  ($#1+($#2-(0,0,0)$)$) --  ($#1+($#2-(0,0,0)$)+($#3-(0,0,0)$)$) 
    -- ($#1+($#3-(0,0,0)$)$) -- cycle}}}
\foreach \Angle in {90,85,...,0}
{\begin{tikzpicture}
    \begin{axis}[hide axis,
        axis equal,
        width=10cm,
        height=10cm,
        axis lines = center,
        xlabel = {$x$},
        ylabel = {$y$},
        zlabel = {$z$},
        ticks=none,
        enlargelimits=0.3,
        view/h=45,
        scale uniformly strategy=units only,
    ]
    \addplot3[%
        opacity = 0.5,
        surf,
        z buffer = sort,
        samples = 21,
        variable = \u,
        variable y = \v,
        domain = 0:180,
        y domain = 0:360,
    ]
    ({cos(u)*sin(v)}, {sin(u)*sin(v)}, {cos(v)});
    \draw[overlay,fill=white,fill opacity=0.4,
    tangent plane=at {({cos(\Angle)-0.5*sin(\Angle)},-0.5,{sin(\Angle)})} with 
    vectors {({sin(\Angle)},0,{-cos(\Angle)})} and {(0,1,0)}];
    \end{axis}
\end{tikzpicture}}
\end{document}

enter image description here

  • 1
    Very interesting, as usual. I believe two of the \edefs can be simplified a bit, because \edef doesn't expand #1, #2, etc. They are just replaced as for \def (that is, after the expansion done by \edef). These work for me: first, the \edef in \VecAdd can be replaced with \def; second: /utils/exec=\def\temp{\VecAdd#1+#2->\myvecOne XXX}, third: as is because of \myvecOne, and fourth: \def\temp{\VecAdd#1+#3->\myvecThree XXX}. – frougon May 21 at 8:03
  • 1
    @frougon Yes, thanks! As you say, it becomes less symmetric if one replaces some \edefs with \defs. But I completely switched gears now, the code is now more powerful in that is also works with symbolic coordinates and is much shorter. Thanks again! – marmot May 21 at 12:13
  • Thanks for showing yet another way! These -(0,0,0) are black magic to me, but since I haven't read about 3D handling in TikZ yet... maybe this is a way to trigger the 3D to 2D-canvas projection? – frougon May 21 at 14:02
  • 1
    @frougon The -(0,0,0) are just because the origin of the 3d coordinate system, (0,0,0), and the origin of the TikZ coordinate system, call it (0,0), do not coincide. And yes, there are such projections, they are can be obtained from canvas is ... plane of the 3d library that is explained in section 40 Three Dimensional Drawing Library of the pgfmanual v 3.1.3. – marmot May 21 at 14:08
  • @marmot Can you explain "the mandatory animation"? Thanks in advance – jpayansomet May 22 at 16:21

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.