Re: [Concorso] TikZ nella gallery del sito

#93222
Up
0
Down
::


Un disegno che ho realizzato per illustrare la geometria di un’eclisse, con un pianeta che occulta la sua stella. Non credo sia l’esempio più bello possibile, però mi piace la sua relativa semplicità del codice:
`\documentclass[tikz]{standalone}
\usepackage[light]{kpfonts}
\usetikzlibrary{calc,intersections}
\begin{document}
\begin{tikzpicture}
\coordinate (O1) at (0,0); % centro stella
\coordinate (O2) at (2.5,0); % centro pianeta
\draw[name path=S,thick] (O1) circle (2); % disco stella (r=2)
\draw[name path=P,thick] (O2) circle (1); % disco pianeta (r=1)
% individuo punti di intersezione fra dischi di pianeta e stella
\path[name intersections={of=S and P,by={A,B}}];
\draw[dashed] (O1) — (A) — (O2) — node[below,sloped] {$r_2$} (B) —
node[above,sloped] {$r_1$} (O1);
\draw (A) — (B);
\draw[->] ($(B) – (0,0.5)$) node[left,fill=white,inner sep=0.4] {$S_1$} to
[out=45,in=-80] (1.9,-0.1);
\draw[->] ($(A) + (0,0.5)$) node

{$S_2$}
to[out=180] (1.7,0.1);
\draw[red,thick] let \n1 = {acos((1-4+2.5*2.5)/(2*1*2.5))} in
($(O2) – cos(\n1)*(0.2,0) + sin(\n1)*(0,0.2)$) arc
(180-\n1:180+\n1:0.2);
\draw[->] ($(O2) + (-0.2,0.5)$) node[red,right] {$\theta_2$}
to[out=180,in=180] (2.3,0);
\draw[blue,thick] let \n2 = {acos((4-1+2.5*2.5)/(2*2*2.5))} in
($(O1) + cos(\n2)*(0.3,0) – sin(\n2)*(0,0.3)$) arc (-\n2:\n2:0.3);
\draw[->] ($(O1) + (0.5,-0.5)$) node[blue,below] {$\theta_1$} to[in=0] (0.3,0);
\end{tikzpicture}
\end{document}`

Sperando che non venga interpretato come un doppio codice e quindi motivo di esclusione dalla gara (:D), riporto anche una versione che fa uso del pacchetto [tt]tkz-euclide[/tt] che evita qualche noioso conto manuale degli arcocoseni.

`\documentclass[tikz]{standalone}
\usepackage[light]{kpfonts}
\usepackage{tkz-euclide}
\usetikzlibrary{calc}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}
\tkzDefPoint (0,0){A} % centro stella
\tkzDefPoint(2.5,0){B} % centro pianeta
\tkzDrawCircle[R,thick](A,2 cm) % disco stella (r=2)
\tkzDrawCircle[R,thick](B,1 cm) % disco pianeta (r=1)
% individuo punti di intersezione fra dischi di pianeta e stella
\tkzInterCC[R](A,2 cm)(B,1 cm)
\tkzGetPoints{C}{D}
\draw[dashed] (A) — (C) — (B) — node[below,sloped] {$r_2$} (D) —
node[above,sloped] {$r_1$} (A);
\draw (C) — (D);
\draw[->] ($(D) – (0,0.5)$) node[left,fill=white,inner sep=0.4] {$S_1$} to
[out=45,in=-80] (1.9,-0.1);
\draw[->] ($(C) + (0,0.5)$) node

{$S_2$} to[out=180] (1.7,0.1);
\tkzFindAngle(D,B,C)
\tkzGetAngle{thetauno}
\draw[red,thick] ($(B) + cos(\thetauno/2)*(0.2,0) + sin(\thetauno/2)*(0,0.2)$)
arc (\thetauno/2:360-\thetauno/2:0.2);
\draw[->] ($(B) + (-0.2,0.5)$) node[red,right] {$\theta_2$}
to[out=180,in=180] (2.3,0);
\tkzFindAngle(D,A,C)
\tkzGetAngle{thetadue}
\draw[blue,thick] ($(A) + cos(\thetadue/2)*(0.3,0) + sin(\thetadue/2)*(0,0.3)$)
arc (\thetadue/2:-\thetadue/2:0.3);
\draw[->] ($(A) + (0.5,-0.5)$) node[blue,below] {$\theta_1$} to[in=0] (0.3,0);
\end{tikzpicture}
\end{document}`

Go to top