如何使用 tikz 绘制两个共用一个顶点的相似三角形?

如何使用 tikz 绘制两个共用一个顶点的相似三角形?

类似下面的图片:

相似三角形共用一个顶点

答案1

一种选择:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles}

\newcommand\MyTri[3]{
% fill the triangle
\fill[gray!30] 
  (0,0) coordinate (0) -- 
  (4,0) coordinate (1) -- 
  (5,2) coordinate (a) -- cycle;
;
% draw the marks for the angles
\path
  pic[draw=black,double=gray!30,angle radius=1cm] {angle={1--0--a}}
  pic[draw=black,angle radius=0.5cm] {angle={a--1--0}};
% draw the triangle
\path[draw] 
  (0) node[below left] {$#1$} -- 
  (1) node[below right] {$#2$} --
  (a) node[right] {$#3$} --
  cycle
  ; 
\foreach \Coor in {0,1,a}
  \node[circle,draw,fill=white,inner sep=1.5pt] at (\Coor) {};  
}

\begin{document}

\begin{tikzpicture}
\MyTri{0}{1}{a}
\begin{scope}[rotate=45,scale=0.8]
\MyTri{0}{b}{ab}
\end{scope}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

这是一种不使用的方法范围界定

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\makeatletter
\newcommand\myanglebetween{\my@anglebetween}
\def\my@anglebetween(#1)(#2)and(#3)(#4)#5{%%
  \pgfmathanglebetweenlines{\pgfpointanchor{#1}{center}}{\pgfpointanchor{#2}{center}}
                           {\pgfpointanchor{#3}{center}}{\pgfpointanchor{#4}{center}}
  \edef#5{\pgfmathresult}}

\newcommand\myveclen{\my@veclen}
\def\my@veclen(#1)(#2)#3{%%
  \pgfpointdiff{\pgfpointanchor{#1}{center}}{\pgfpointanchor{#2}{center}}
  \edef\ae@pt@x{\pgf@x}
  \edef\ae@pt@y{\pgf@y}
  \pgfmathveclen{\ae@pt@x}{\ae@pt@y}
  \edef#3{\pgfmathresult}}

\makeatother

\begin{document}

\def\mydistb{6cm}

\begin{tikzpicture}

  \coordinate (A) at (0,0);
  \coordinate (B) at (3,1);
  \coordinate (C) at (5,4);

  \draw (A) -- (B) -- (C) -- cycle;

  %% measure of the angle CAB
  \myanglebetween(A)(B)and(A)(C)\anglea

  %% the length to "AB"
  \myveclen(A)(B)\mylenAB

  %% the length to "AC"
  \myveclen(A)(C)\mylenAC

  %% scale factor
  \pgfmathparse{\mydistb/\mylenAB}
  \edef\myscalefactor{\pgfmathresult}  

  \coordinate (B')  at ($(A)+(80:\mydistb)$);
  \coordinate (C')  at ($(A)!\myscalefactor*\mylenAC pt!\anglea:(B')$);

  \draw (A) -- (B') -- (C') -- cycle;

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容