見出し画像

TikZ 実用例(2)~三角形の外接円~

続いて

3辺の長さを入力すれば三角形とその外接円を自動で描くコード

です。

\begin{tikzpicture}[scale=1]
\tikzmath{
  \a = 7; %底辺の長さ
  \b = 5; %右側の辺の長さ
  \c = 8; %左側の辺の長さ
  \A = acos((\b^2+\c^2-\a^2)/(2*\b*\c));
  \B = acos((\c^2+\a^2-\b^2)/(2*\c*\a));
  \C = acos((\a^2+\b^2-\c^2)/(2*\a*\b));
  \R = \a/(2*sin(\A));
}
\coordinate (B) at (0,0);
\coordinate (A) at (\B:\c);
\coordinate (C) at (0:\a);
\coordinate[label=above:O] (O) at (90-\A:\R);
\draw (O) circle[radius=\R];
\draw[thick] (A)--(B)--(C)--cycle;
\draw[dashed,very thin]
(B) to[bend right=20] node[fill=white,midway]{$\a$} (C)
(C) to[bend right=20] node[fill=white,midway]{$\b$} (A)
(A) to[bend right=20] node[fill=white,midway]{$\c$} (B);
\fill (O) circle[radius=2pt];
\foreach \P in{A,B,C} \draw ($(O)!11/10!(\P)$) node{\P};
\end{tikzpicture}

これをコンパイルすると、こんな感じ♪

画像1

最初の方の \a, \b, \c の値を変えることで、いろいろなパターンを自動的に描けます♪

この記事が気に入ったらサポートをしてみませんか?