TikZ:旋转范围改变阴影

TikZ:旋转范围改变阴影

作为后续行动这个问题,土星的倾斜度为 26°。但是当我倾斜土星时,环的颜色会发生变化。

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\begin{scope}[rotate=26.73]
% Top half
\fill [gray!30] (0:1) arc (0:180:1) -- cycle;

% Ring
\path[inner color=black,outer color=yellow!20,even odd rule]    
    (0, 0) circle [x radius = 1.5, y radius = .25]
    (0, 0) circle [x radius = 1.7, y radius = .3]
    (0, 0) circle [x radius = 1.75, y radius = .33]
    (0, 0) circle [x radius = 1.95, y radius = .38]; 

% Bottom half
\fill [gray!30] (180:1) arc (180:360:1) -- cycle;
\end{scope}
\end{tikzpicture}
\end{document}

以下是我使用rotate=0和获得的结果rotate=26.73

无旋转 带旋转

我想要得到的 目标

如何让圆环旋转而不改变其颜色?如何让阴影随物体一起旋转?

我尝试添加shading angle=26.73,但颜色仍然不正确:

\begin{tikzpicture}
\begin{scope}[rotate=26.73]
% Top half
\fill [gray!30] (0:1) arc (0:180:1) -- cycle;

% Ring
\path[inner color=black,outer color=yellow!20, even odd rule, shading angle=26.73]    
    (0, 0) circle [x radius = 1.5, y radius = .25]
    (0, 0) circle [x radius = 1.7, y radius = .3]
    (0, 0) circle [x radius = 1.75, y radius = .33]
    (0, 0) circle [x radius = 1.95, y radius = .38]; 

% Bottom half
\fill [gray!30] (180:1) arc (180:360:1) -- cycle;
\end{scope}
\end{tikzpicture}

还导致带旋转

答案1

可以\rotatebox接受嗎?

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\rotatebox{26.73}{%
\begin{tikzpicture}
% Top half
\fill [gray!30] (0:1) arc (0:180:1) -- cycle;

% Ring
\path[inner color=black,outer color=yellow!20,even odd rule]    
(0, 0) circle [x radius = 1.5, y radius = .25]
(0, 0) circle [x radius = 1.7, y radius = .3]
(0, 0) circle [x radius = 1.75, y radius = .33]
(0, 0) circle [x radius = 1.95, y radius = .38]; 

% Bottom half
\fill [gray!30] (180:1) arc (180:360:1) -- cycle;
\end{tikzpicture}%
}
\end{document}

在此处输入图片描述

编辑

嗯,明白了。您可以将整个代码包含在节点内:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% Top half
\node[rotate=26.37] at (0,0) {%
\begin{tikzpicture}
\fill [gray!30] (0:1) arc (0:180:1) -- cycle;

% Ring
\path[inner color=black,outer color=yellow!20,even odd rule]    
(0, 0) circle [x radius = 1.5, y radius = .25]
(0, 0) circle [x radius = 1.7, y radius = .3]
(0, 0) circle [x radius = 1.75, y radius = .33]
(0, 0) circle [x radius = 1.95, y radius = .38]; 

% Bottom half
\fill [gray!30] (180:1) arc (180:360:1) -- cycle;
\end{tikzpicture}
};
\end{tikzpicture}%
\end{document}

在此处输入图片描述

答案2

这是一个解决方案:

\documentclass[tikz]{standalone}
\begin{document}
\foreach \tilt in {-21.6,-21.2,...,21.6,21.2,20.8,...,-21.2}{
  \begin{tikzpicture}
    \fill[white] (-2.3,-1.3) rectangle (2.3,1.3);
    \begin{scope}[rotate=\tilt]
      % Top half
      \fill [gray!30] (0:1) arc (0:180:1) -- cycle;
      \colorlet{yellowhite}{yellow!20!white}
      \foreach \xrad[
      evaluate={\xrad as \yrad using \xrad/5.13},
      evaluate={\xrad as \cprop using int(\xrad/2.28*100)},
      ]in {1.5,1.52,...,1.8,1.98,2.00,...,2.28} {
        \fill[fill=yellowhite!\cprop!black,even odd rule]
        (0,0 ) circle [x radius=\xrad, y radius=\yrad]
        (0,0 ) circle [x radius=\xrad+0.02,y radius=\yrad+0.02/5.13];
      }
      % Bottom half
      \fill [gray!30] (180:1) arc (180:360:1) -- cycle;
    \end{scope}
  \end{tikzpicture}
}
\end{document}

在此处输入图片描述

相关内容