我想知道是否可以在 pgfplots 中安装 3D 球面坐标(不是 Ti钾Z)这类问题已经有人问过了,但据我所知,答案这里,这里,这里和这里都将转换写在参数中,因此它们会执行类似以下操作:
\addplot3[...] ({cos(x)*cos(y)},{cos(x)*sin(y)},{1 + 0.2*sin(x)*sin(y)});
在这个问题中,我要求的是不同的东西。在平淡的 Ti钾Z 一个可能切换到球面坐标,如 MWE 所示
\documentclass{article}
\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{3d}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\makeatletter
\newcommand{\SwitchToPolar}{% based on https://tex.stackexchange.com/a/365418/121799
\def\tikz@parse@splitxyz##1##2##3,##4,{%
\def\@next{\tikz@scan@one@point##1(xyz spherical cs:angle=##2,radius=##3,latitude=##4 r)}%
}}
\newcommand{\SwitchToNormal}{%
\def\tikz@parse@splitxyz##1##2##3,##4,{%
\def\@next{##1{\pgfpointxyz{##2}{##3}{##4}}}%
}}
\makeatother
\begin{document}
\section*{With ordinary tikz pictures it works\dots}
\begin{tikzpicture}
\draw[-latex] (0,0,0) -- (2,0,0) node[below]{$x$};
\draw[-latex] (0,0,0) -- (0,2,0) node[left]{$y$};
\draw[-latex] (0,0,0) -- (0,0,2) node[below]{$z$};
\SwitchToPolar
\draw[blue] plot[variable=\x,domain=0:200,samples=200,smooth]
({17*\x},2,{\x/80});
\SwitchToNormal
\end{tikzpicture}
\section*{\dots but not yet with pgfplots}
\begin{tikzpicture}
%\SwitchToPolar
\begin{axis}
\SwitchToPolar
\addplot3[blue,domain=0:200,samples=20,
%execute at begin plot={\SwitchToPolar}
] ({17*x},2,{x/80});
\end{axis}
\end{tikzpicture}
I also played with \texttt{x coord trafo/.code} and
\texttt{x filter/.code}, of course also for $y$ and $z$. The problem with
\texttt{x coord trafo/.code} is that it only has one parameter, i.e.\ the
transformation of $x$ cannot depend on $y$ nor $z$, and likewise for $y$ and
$z$. Further, \verb|\rawx| is not available for these transformations as well.
\section*{Question: Is there a trick to install spherical 3D coordinates for pgfplots?}
\end{document}
如您所见,坐标变化已被忽略。有什么方法可以让它起作用吗?(在 MWE 中,我列出了我尝试过但不起作用的方法。)
这可能有什么好处?我想这只会让一些事情变得更简单。毕竟,pgfplots 确实有 2D 极坐标。