tikz 制作的精美图片

tikz 制作的精美图片

我盯着这张美丽的图片看了 3 个小时,我真的很想知道如何使用 tikz 来实现它。如果有人有想法的话。在此处输入图片描述

答案1

您只需要加载几个库即可。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc,through,angles,backgrounds}
\tikzset{circle through 3 points/.style n args={3}{% https://tex.stackexchange.com/a/461180/121799
insert path={let    \p1=($(#1)!0.5!(#2)$),
                    \p2=($(#1)!0.5!(#3)$),
                    \p3=($(#1)!0.5!(#2)!1!-90:(#2)$),
                    \p4=($(#1)!0.5!(#3)!1!90:(#3)$),
                    \p5=(intersection of \p1--\p3 and \p2--\p4)
                    in },
at={(\p5)},
circle through= {(#1)}
}}
\xdef\MyColors{% borrowed from https://tex.stackexchange.com/a/208864/121799
"red",
"red!25",
"magenta",
"magenta!25",
"olive",
"olive!25",
"brown",
"brown!10",
"violet",
"violet!25",
"gray",
"purple",
"yellow",
"orange",
"orange!25",
"cyan",
"green"}%
\newcounter{col}
\begin{document}
\begin{tikzpicture}[every label/.append style={text=black}]
 \draw[green!80!black] 
 (5,3)  coordinate[label=right:$A$] (A)
 -- (1,6) coordinate[label=above left:$B$] (B) 
 -- (0,0) coordinate[label=below left:$C$] (C)   --cycle;
 \draw[purple,thick] foreach \X/\Y [remember=\X as \Z (initially C)] in {A/B,B/C,C/A}
 {(\Y) -- ($(\X)!(\Y)!(\Z)$) coordinate (H\Y) node[pos=1.1] {$H_{\Y}$}};
 \path  (intersection cs:first line={(HC)--(C)}, second line={(HA)--(A)})
 coordinate[label={[text=yellow]above:$H$}] (H);
 \begin{scope}[on background layer]
  \draw[green!80!black,fill=green] (HA) -- (HB) -- (HC) -- cycle;
 \path foreach \X/\Y [remember=\X as \Z (initially C)] in {A/B,B/C,C/A}
 {node[draw=cyan,circle through 3 points={H\X}{H\Y}{\Z}](sc\Z){} 
  node[draw=cyan,circle through 3 points={H\X}{\Y}{\X}](bc\X){}
 [/utils/exec=\stepcounter{col}\pgfmathsetmacro{\mycolor}{{\MyColors}[\number\value{col}]}]
  pic[fill=\mycolor] {angle = H\X--\Y--\X}
 [/utils/exec=\stepcounter{col}\pgfmathsetmacro{\mycolor}{{\MyColors}[\number\value{col}]}]
  pic[fill=\mycolor] {angle = H\X--H\Y--\Z}
  pic[fill=\mycolor] {angle = \X--H\Y--H\Z}
  [/utils/exec=\stepcounter{col}\pgfmathsetmacro{\mycolor}{{\MyColors}[\number\value{col}]}]
  pic[fill=\mycolor] {angle = H\Z--H\Y--H\X}   
  [/utils/exec=\stepcounter{col}\pgfmathsetmacro{\mycolor}{{\MyColors}[\number\value{col}]}]
  pic[fill=\mycolor] {angle = H\Y--H--\X}
  pic[fill=\mycolor] {angle = \Y--H--H\X}
    };
 \end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

或者

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc,through,angles,backgrounds}
\tikzset{circle through 3 points/.style n args={3}{% https://tex.stackexchange.com/a/461180/121799
insert path={let    \p1=($(#1)!0.5!(#2)$),
                    \p2=($(#1)!0.5!(#3)$),
                    \p3=($(#1)!0.5!(#2)!1!-90:(#2)$),
                    \p4=($(#1)!0.5!(#3)!1!90:(#3)$),
                    \p5=(intersection of \p1--\p3 and \p2--\p4)
                    in },
at={(\p5)},
circle through= {(#1)}
}}
\xdef\MyColors{% borrowed from https://tex.stackexchange.com/a/208864/121799
"red",
"red!25",
"magenta",
"magenta!25",
"olive",
"olive!25",
"brown",
"brown!10",
"violet",
"violet!25",
"gray",
"purple",
"yellow",
"orange",
"orange!25",
"cyan",
"green"}%
\newcounter{col}
\begin{document}
\begin{tikzpicture}[every label/.append style={text=black},
 next color/.code={\stepcounter{col}\pgfmathsetmacro{#1}{{\MyColors}[\number\value{col}]}},
 angle factor/.style args={#1--#2--#3}{insert path={
 let \p1=($(#1)-(#2)$),\p2=($(#3)-(#2)$),
 \n1={1/abs(sin(atan2(\y1,\x1)-atan2(\y2,\x2)))} in % \pgfextra{\typeout{\n1}}
 }}]
 \draw[green!80!black] 
 (5,3)  coordinate[label=right:$A$] (A)
 -- (1,6) coordinate[label=above left:$B$] (B) 
 -- (0,0) coordinate[label=below left:$C$] (C)   --cycle;
 \draw[purple,thick] foreach \X/\Y [remember=\X as \Z (initially C)] in {A/B,B/C,C/A}
 {(\Y) -- ($(\X)!(\Y)!(\Z)$) coordinate (H\Y) node[pos=1.1] {$H_{\Y}$}};
 \path  (intersection cs:first line={(HC)--(C)}, second line={(HA)--(A)})
 coordinate[label={[text=yellow]above:$H$}] (H);
 \begin{scope}[on background layer]
  \draw[green!80!black,fill=green] (HA) -- (HB) -- (HC) -- cycle;
 \path foreach \X/\Y [remember=\X as \Z (initially C)] in {A/B,B/C,C/A}
 {node[draw=cyan,circle through 3 points={H\X}{H\Y}{\Z}](sc\Z){} 
  node[draw=cyan,circle through 3 points={H\X}{\Y}{\X}](bc\X){}
 [next color=\mycolor,angle factor={H\X--\Y--\X}]
  pic[fill=\mycolor,angle radius=\n1*5mm] {angle = H\X--\Y--\X}
 [next color=\mycolor,angle factor={H\X--H\Y--\Z}]
  pic[fill=\mycolor,angle radius=\n1*5mm] {angle = H\X--H\Y--\Z}
 [angle factor={\X--H\Y--H\Z}] 
  pic[fill=\mycolor,angle radius=\n1*5mm] {angle = \X--H\Y--H\Z}
 [next color=\mycolor,angle factor={H\Z--H\Y--H\X}]
  pic[fill=\mycolor,angle radius=\n1*5mm] {angle = H\Z--H\Y--H\X}   
 [next color=\mycolor,angle factor={H\Y--H--\X}]
  pic[fill=\mycolor,angle radius=\n1*5mm] {angle = H\Y--H--\X}
 [angle factor={\Y--H--H\X}] 
  pic[fill=\mycolor,angle radius=\n1*5mm] {angle = \Y--H--H\X}
    };
 \end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容