我想绘制月相并从此代码开始
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{\node[shape=circle,draw,inner sep=2pt,fill=white] (char) {#1};}}
\begin{document}
\begin{tikzpicture}
\draw (0cm,0cm) circle(4cm);
\foreach \x in {0,45,...,360} {
\filldraw[fill=white] (\x:4cm) circle(0.4cm);
\filldraw[fill=white] (\x:5cm) circle(0.4cm);
\draw[fill=black!70] (\x:4cm)-- +(0,0.4cm) arc (90:-90:0.4cm) -- cycle;
}
\node[inner sep=0pt] at (0,0) {\includegraphics[height=5cm]{aarde2}};
\foreach \x/\xtext in {
0/\circled{5},
45/\circled{6},
90/\circled{7},
135/\circled{8},
180/\circled{1},
225/\circled{2},
270/\circled{3},
315/\circled{4}}
\draw (\x:3.3cm) node {\tiny \xtext};
\end{tikzpicture}
\end{document}
结果是:
(地球的图片未上传)
我的问题是:如何在白色圆圈周围绘制正方形。由于圆圈的半径为 8 毫米,因此正方形的边长应为 1 厘米。
(白色圆圈的目的是当您站在那个位置时,给月相的真实视图着色。
答案1
这是错误的方式,但无论如何......
\documentclass[tikz,border=5]{standalone}
\colorlet{color 0}{white}
\colorlet{color 1}{black}
\begin{document}
\begin{tikzpicture}
\filldraw [fill=color 0] circle [radius=1.5];
\filldraw [fill=color 1] (90:1.5) arc (90:270:1.5) -- cycle;
\draw (0, 0) circle [radius=4];
\foreach \phase [count=\i,evaluate={\a=\i*45-45; \j=int(mod(\i-1, 4));
\ca=int(\i>4); \cb=int(\i<5);}]
in {New moon, Waxing crescent, First quarter, Waxing gibbous,
Full moon, Waning gibbous, Last quarter, Waning crescent}{
\filldraw [fill=color 0] (\a:4) circle [radius=0.5];
\filldraw [fill=color 1] (\a:4) ++(90:0.5) arc (90:270:0.5) -- cycle;
\begin{scope}[shift=(\a:6), scale=0.75]
\fill [gray!50] (-1.125, -1.125) rectangle (1.125, 1.125);
\fill [fill=color \cb] circle [radius=1];
\ifcase\j
\or
\fill [color \ca] (90:1) arc (45:-45:sqrt 2) arc (-90:90:1) -- cycle;
\or
\fill [color \ca] (90:1) arc (90:-90:1) -- cycle;
\or
\fill [color \ca] (90:1) arc (135:225:sqrt 2) arc (-90:90:1) -- cycle;
\fi
\node [anchor=(\i>4)*180-90, align=center, text width=5em]
at ({(\i>4)*180+90}:1.125) {\phase};
\end{scope}
\node [circle, draw] at (\a:3) {\i};
}
\end{tikzpicture}
\end{document}
答案2
更换\circled
:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\draw (0cm,0cm) circle(4cm);
\foreach \x in {0,45,...,360} {
\filldraw[fill=white] (\x:4cm) circle(0.4cm);
\filldraw[fill=white] (\x:5cm) circle(0.4cm);
\draw (\x:5cm) +(-.5cm,-.5cm) rectangle +(.5cm,.5cm);
\draw[fill=black!70] (\x:4cm)-- +(0,0.4cm) arc (90:-90:0.4cm) -- cycle;
}
\node[inner sep=0pt] at (0,0) {\includegraphics[height=5cm]{aarde2}};
\foreach \x/\xtext in {
0/5,
45/6,
90/7,
135/8,
180/1,
225/2,
270/3,
315/4}
\draw (\x:3.3cm) node[shape=circle,draw,inner sep=2pt,fill=white] {\tiny \xtext};
\end{tikzpicture}
\end{document}