使用 tikz 的 3D 坐标绘制 2D 形状

使用 tikz 的 3D 坐标绘制 2D 形状

我尝试绘制由太阳-金星-地球组成的行星系统。我的代码是

\begin{tikzpicture}[scale=0.1]
%-> DEFINITIONS
%... sizes
\def\srad{10}
\def\erad{3}
\def\eorb{60}
\def\vrad{0.3}
\def\vorb{0.7*\eorb}

\begin{scope}[canvas is zx plane at y=0]
    \draw[very thick]
        (0,0) circle(\srad)
            node{Sun}
        (60:\vorb) circle(\vrad)
        (60:\eorb) circle(\erad)
        ;
    \draw[->, thick, dotted]
        (50:\vorb)
            node[below]{Venus}
            arc(50:120:\vorb)
        ;
    \draw[->, thick, dotted]
        (50:\eorb)
            node[below]{Earth}
            arc(50:120:\eorb)
        ;
\end{scope}
\end{tikzpicture}

问题:如何在 zx 平面上绘制圆而不变形,但保持圆弧与原来完全相同?

答案1

当然。你只需要在范围内定义这些对象的中心坐标canvas is zx plane at y=0,并在范围外围绕这些中心绘制圆圈即可。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{3d}
% fix wrong implementation of xy canvas https://tex.stackexchange.com/a/48776/121799
\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
  \def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
  \def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
  \def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
  \tikz@canvas@is@plane
}
\makeatother
\begin{document}
\begin{tikzpicture}[scale=0.1]
%-> DEFINITIONS
%... sizes
\def\srad{10}
\def\erad{3}
\def\eorb{60}
\def\vrad{0.3}
\def\vorb{0.7*\eorb}

\begin{scope}[canvas is zx plane at y=0]
    \path
        (0,0) coordinate (Sun)
        (60:\vorb) coordinate (Venus)
        (60:\eorb) coordinate (Earth)
        ;
    \draw[->, thick, dotted]
        (50:\vorb)
            node[below]{Venus}
            arc(50:120:\vorb)
        ;
    \draw[->, thick, dotted]
        (50:\eorb)
            node[below]{Earth}
            arc(50:120:\eorb)
        ;
\end{scope}
\draw[very thick]
    (Sun) circle(\srad)  node{Sun}
    (Venus) circle(\vrad)
    (Earth) circle(\erad);
\end{tikzpicture}
\end{document}

在此处输入图片描述

如果您也想更改视图,我建议您加载tikz-3dplot

相关内容