创建三角形解决问题

创建三角形解决问题

我希望创建一个三角形求解问题生成器,类似于这里

我的目标是为我的学生自动生成不同的三角形求解问题。假设给定A=49°b=5c=7,我希望程序能够生成下面的图片。同样,如果系统允许我通过其他公理(例如 SSS、ASA)输入三角形数据,那就太好了。

tikz-pgf在这里做了标记,但也欢迎使用其他绘图语言。

在此处输入图片描述

答案1

这里有一个答案tkz-euclide

问题第二部分的解决方案:如何使用 SSS、SAS 和 ASA 这是我的解决方案:

示例中的 SSS、SAS 和 ASA

\documentclass{standalone} 
\usepackage{tkz-euclide}
\makeatletter
\def\opttr{0}
\pgfkeys{/defTriangle/.cd,
SSS/.code args={a=#1 b=#2 c=#3}{%
                                  \def\a{#1}%
                                  \def\b{#2}%
                                  \def\c{#3}
                                  \def\opttr{0}},
SAS/.code args={b=#1 A=#2 c=#3}{%
                                  \def\b{#1}%
                                  \def\A{#2}%
                                  \def\c{#3}
                                  \def\opttr{1}},
ASA/.code args={A=#1 c=#2 B=#3}{%
                                  \def\A{#1}%
                                  \def\c{#2}%
                                  \def\B{#3}
                                  \def\opttr{2}}} 
\def\DefTriangle[#1]#2{% 
\begingroup 
\pgfqkeys{/defTriangle}{#1}    
 \ifcase\opttr% 
   \ThreeSide(\a,\b,\c)(#2)
   \or
   \TwoSide(\b,\A,\c)(#2)
   \or
   \OneSide(\A,\c,\B)(#2)
\fi    
\endgroup
}

\def\ThreeSide(#1,#2,#3)(#4,#5,#6){%
\begingroup 
\tkzDefPoints{0/0/#4,#3/0/#5}
\tkzInterCC[R](#4,#2 cm)(#5,#1 cm) \tkzGetFirstPoint{#6}
\endgroup}

\def\TwoSide(#1,#2,#3)(#4,#5,#6){%
\begingroup 
\tkzDefPoints{0/0/#4,#3/0/#5}
\tkzDefPoint(#2:#1){#6}
\endgroup}

\def\OneSide(#1,#2,#3)(#4,#5,#6){%
\begingroup 
\tkzDefPoints{0/0/#4,#2/0/#5}
  \tkzDefPointBy[rotation= center #4 angle \A](#5)
  \tkzGetPoint{a}
  \tkzDefPointBy[rotation= center #5 angle -\B](#4)
  \tkzGetPoint{b}
  \tkzInterLL(#4,a)(#5,b)
  \tkzGetPoint{#6}
\endgroup}
\makeatother

\begin{document} 

\begin{tikzpicture}
  \DefTriangle[SSS={a=4 b=5 c=5}]{A,B,C}
  \tkzDrawPolygon(A,B,C)
  \tkzDrawPoints(A,B,C)
  \tkzLabelPoints[below](A,B)
  \tkzLabelPoints[above](C)
\end{tikzpicture}

\begin{tikzpicture}
  \DefTriangle[SAS={b=4 A=30 c=5}]{D,E,F}
  \tkzDrawPolygon(D,E,F)
  \tkzDrawPoints(D,E,F)
  \tkzLabelPoints[below](D,E)
  \tkzLabelPoints[above](F)
\end{tikzpicture}

 \begin{tikzpicture}
   \DefTriangle[ASA={A=30 c=10 B=60}]{A,B,C}
   \tkzDrawPolygon(A,B,C)
   \tkzDrawPoints(A,B,C)
   \tkzLabelPoints[below](A,B)
   \tkzLabelPoints[above](C)
 \end{tikzpicture}

\end{document} 

在此处输入图片描述

A)最简单的解决方案:

\documentclass{standalone}
\usepackage{tkz-euclide}
\begin{document}\begin{tikzpicture}
 %def
 \tkzDefPoints{0/0/A,7/0/B}
  \tkzDefPoint(49:5){C}
  % draw
  \tkzDrawPolygon(A,B,C)
  \tkzDrawPoints(A,B,C)
  %marks
  \tkzMarkAngle[size=1.3cm](B,A,C)
  %label
  \tkzLabelSegment[below](A,B){$ 7 $}
  \tkzLabelSegment[left](A,C){$ 5 $}
  \tkzLabelSegment[right](B,C){$ a $}
  \tkzLabelAngle[pos = 0.8](B,A,C){$49^\circ$}
  \tkzLabelPoints(A,B)
  \tkzLabelPoints[above](C)
\end{tikzpicture}
\end{document} 

B) 更复杂的解决方案,以了解包的一些可能性。

没什么可说的A and B

然后你需要使用一个角度的特殊值。你可以使用旋转。你得到一个点c

最后一个宏更微妙...使用选项,linear您可以得到 Ac 线上的一个点,然后 linear normed使用 得到一个点C,例如,AC=1然后使用linear normed,K=5得到AC=5。就这样。您有三个点 A、B 和 C。您可以将 tkz-euclide 与 TikZ 的选项一起使用,也可以只使用 TikZ。

\documentclass{standalone}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}
 % def
  \tkzDefPoints{0/0/A,7/0/B}
  \tkzDefPointBy[rotation= center A angle 49](B)
  \tkzGetPoint{c}
  \tkzDefPointWith[linear normed ,K=5](A,c)
  \tkzGetPoint{C}
 % drawing
  \tkzDrawPolygon(A,B,C)
  \tkzDrawPoints(A,B,C)
 % marking
  \tkzMarkAngle[size=1.3cm](B,A,C)
 % labelling
  \tkzLabelSegment[below](A,B){$ 7 $}
  \tkzLabelSegment[left](A,C){$ 5 $}
  \tkzLabelSegment[right](B,C){$ a $}
  \tkzLabelAngle[pos = 0.8](B,A,C){$49^\circ$}
  \tkzLabelPoints(A,B)
  \tkzLabelPoints[above](C)
\end{tikzpicture}
\end{document}

在此处输入图片描述

C)minhthien_2016 的解决方案包含更多 tkz-euclide 宏

\documentclass{standalone}
\usepackage{tkz-euclide}
\begin{document}

\begin{tikzpicture}[declare function={a=5;b=7;myAngle=49;}] 
\path (0,0)  coordinate  (B)
({sqrt(a*a+b*b-2*a*b*cos(myAngle))},0)  coordinate  (C)
({b*b -a*b*cos(myAngle))/sqrt(a*a+b*b-2*a*b*cos(myAngle))}
,{a*b*sin(myAngle)/sqrt(a*a+b*b-2*a*b*cos(myAngle))})  coordinate  (A)
;

\tkzDrawPoints(A,B,C)
\tkzLabelPoints(A,B)
\tkzLabelPoints[above](C)
\tkzLabelSegment[above](A,B){$ 7 $}
\tkzDrawPolygon(A,B,C)
\tkzLabelSegment[right](A,C){$ 5 $}
\tkzLabelSegment[below](B,C){$ a $}
\tkzLabelAngle[pos = 0.8](B,A,C){$49^\circ$}
\tkzMarkAngle[size=1.3cm](B,A,C)
\end{tikzpicture}

\end{document}

D)minhthien_2016 的解决方案仅使用 tkz-euclide 宏

问题是 $tkz-euclide usesxfp to evaluate the coordinates so I need to determine these coordinates before a call to\tkzDefPoint

\documentclass{article}
\usepackage{tkz-euclide}
\begin{document}

\begin{tikzpicture}[declare function={a=5;b=7;myAngle=49;}] 

\pgfmathparse{sqrt(a*a+b*b-2*a*b*cos(myAngle))}
\let\xc\pgfmathresult
\pgfmathparse{b*b-a*b*cos(myAngle))/sqrt(a*a+b*b-2*a*b*cos(myAngle))}
\let\xa\pgfmathresult
\pgfmathparse{a*b*sin(myAngle)/sqrt(a*a+b*b-2*a*b*cos(myAngle))}
\let\ya\pgfmathresult

\tkzDefPoints{\xa/\ya/A,0/0/B,\xc/0/C}
\tkzDrawPoints(A,B,C)
\tkzLabelPoints(A,B)
\tkzLabelPoints[above](C)
\tkzLabelSegment[above](A,B){$ 7 $}
\tkzDrawPolygon(A,B,C)
\tkzLabelSegment[right](A,C){$ 5 $}
\tkzLabelSegment[below](B,C){$ a $}
\tkzLabelAngle[pos = 0.8](B,A,C){$49^\circ$}
\tkzMarkAngle[size=1.3cm](B,A,C)
\end{tikzpicture}

\end{document}

在此处输入图片描述

E)tkz-euclidexfp

\documentclass{standalone}
\usepackage{tkz-euclide}
\begin{document}

\begin{tikzpicture}
\def\a{5}  \def\b{7}  \def\myangle{49}
\tkzDefPoints{{(\b*\b -\a*\b*cos(\myangle))/sqrt(\a*\a+\b*\b-2*\a*\b*cos(\myangle))}%
             /{\a*\b*sin(-\myangle)/sqrt(\a*\a+\b*\b-2*\a*\b*cos(\myangle))}/A,%
               0/0/B,%
              {sqrt(\a*\a+\b*\b-2*\a*\b*cos(\myangle))}/0/C}
\tkzDrawPoints(A,B,C)
\tkzLabelPoints(A,B)
\tkzLabelPoints[above](C)
\tkzLabelSegment[above](A,B){$ 7 $}
\tkzDrawPolygon(A,B,C)
\tkzLabelSegment[right](A,C){$ 5 $}
\tkzLabelSegment[below](B,C){$ a $}
\tkzLabelAngle[pos = 0.8](B,A,C){$49^\circ$}
\tkzMarkAngle[size=1.3cm](B,A,C)
\end{tikzpicture}

\end{document}

F)有三条边

\documentclass{standalone}
\usepackage{tkz-euclide}

\begin{document}
  \begin{tikzpicture}
    \pgfmathsetmacro{\a}{3} % BC
    \pgfmathsetmacro{\b}{5} % AC
    \pgfmathsetmacro{\c}{7} % AB

  \tkzDefPoints{0/0/A,\c/0/B}
  \tkzInterCC[R](A,\b cm)(B,\a cm) \tkzGetFirstPoint{C}
  \tkzDrawPolygon(A,B,C) 
  \tkzLabelSegment[below](A,B){$ 7 $}
  \tkzLabelSegment[above left](A,C){$ 5 $}
  \tkzLabelSegment[above right](B,C){$ 3 $}
  \tkzLabelPoints[below](A,B)
  \tkzLabelPoints[above](C)
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

你可以尝试一下这个代码。

\documentclass[border=2mm,12pt]{standalone}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}[
declare function={a=5;b=7;myAngle=49;}] 
\path (0,0)  coordinate  (B)
({sqrt(a*a+b*b-2*a*b*cos(myAngle))},0)  coordinate  (C)
({(b*b - a*b*cos(myAngle))/sqrt(a*a+b*b-2*a*b*cos(myAngle))},{a*b*sin(myAngle)/sqrt(a*a+b*b-2*a*b*cos(myAngle))})  coordinate  (A)
;
\foreach \p in {A,B,C}
\draw[fill=black] (\p) circle (1.5pt);
\foreach \p/\g in {A/90,B/-90,C/-90}
\path (\p)+(\g:3mm) node{$\p$};
\draw (A) -- (B) node[midway,above]{$ 7 $};
\draw (A) -- (C) node[midway,right]{$ 5 $};
\draw (B) -- (C) node[midway,below]{$ a $};
\tkzLabelAngle[pos = 0.8](B,A,C){$49^\circ$}
\tkzMarkAngle[size=1.3cm](B,A,C)
\end{tikzpicture}
\end{document} 

在此处输入图片描述

您可以改变这些值a, b, myAngle

\documentclass[border=2mm,12pt]{standalone}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}[
    declare function={a=5;b=3;myAngle=120;}] 
 \path (0,0)  coordinate  (B)
 ({sqrt(a*a+b*b-2*a*b*cos(myAngle))},0)  coordinate  (C)
 ({(b*b - a*b*cos(myAngle))/sqrt(a*a+b*b-2*a*b*cos(myAngle))},{a*b*sin(myAngle)/sqrt(a*a+b*b-2*a*b*cos(myAngle))})  coordinate  (A)
 ;
 \foreach \p in {A,B,C}
 \draw[fill=black] (\p) circle (1.5pt);
 \foreach \p/\g in {A/90,B/-90,C/-90}
 \path (\p)+(\g:3mm) node{$\p$};
 \draw (A) -- (B) node[midway,above]{$ a $};
 \draw (A) -- (C) node[midway,above]{$ b $};
 \draw (B) -- (C) node[midway,below]{$ \sqrt{a^2 + b^2 - 2ab\cos \alpha } $};
\tkzLabelAngle[pos = 0.3](B,A,C){$\alpha$}
\tkzMarkAngle[size=0.8cm](B,A,C)
\end{tikzpicture}
\end{document} 

在此处输入图片描述

已知三角形的三条边(SSSTriangle),您可以使用此代码。在此代码中,三角形ABC,其中AB=c, BC = a, AC = b

\documentclass[12pt, border = 1mm]{standalone}
\usepackage{tkz-euclide}
\usepackage{tikz}
\begin{document}
     \begin{tikzpicture}[scale=1,declare function={a=3;b=5;c=7;}]
\coordinate (A) at (0,0);
\coordinate (B) at (c,0);
\coordinate (C) at  ({(pow(b,2) + pow(c,2) - pow(a,2))/(2*c)},{sqrt((a+b-c) *(a-b+c) *(-a+b+c)* (a+b+c))/(2*c)});
\foreach \p in {A,B,C}
\draw[fill=black] (\p) circle (1.5pt);
\foreach \p/\g in {A/180,C/90,B/-90}
\path (\p)+(\g:3mm) node{$\p$};
%\draw (A) -- (B) -- (C) -- cycle;
\draw (A) -- (B) node[midway,below]{$  7 $};
\draw (A) -- (C) node[midway,above]{$ 5 $};
\draw (B) -- (C) node[midway,above]{$ 3 $};
\end{tikzpicture}
\end{document}

在此处输入图片描述

三角形ABC,认识角ABAB

\documentclass[border=2mm,12pt]{standalone}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}[scale=1,declare function={c=3;AngleA=30;AngleB=90;}]
\coordinate (A) at (0,0);
\coordinate (B) at (c,0);
\coordinate (C) at  ({c*cos (AngleA)* cosec(AngleA + AngleB) *sin(AngleB)}, {c* cosec(AngleA + AngleB)*sin (AngleA)* sin (AngleB)});
\foreach \p in {A,B,C}
\draw[fill=black] (\p) circle (1.5pt);
\foreach \p/\g in {A/-90,C/90,B/-90}
\path (\p)+(\g:3mm) node{$\p$};
\draw (A) -- (B) -- (C) -- cycle;
\end{tikzpicture}
\end{document} 

在此处输入图片描述

答案3

这是使用图片的另一个版本。您可以指定边、abc或者两条边和一个角,或者一条边和两个角。它现在应该涵盖所有可能的情况。但是,如果解决方案不是唯一的,它将选择一个解决方案。此外,还没有对所有可能的输入进行健全性检查,但有一些。代码不是很短,这可能是为了某种用户友好性而必须付出的代价。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles,calc}
\tikzset{pics/triangle/.style={code={
    \tikzset{triangle pars/.cd,#1}%
    \def\pv##1{\pgfkeysvalueof{/tikz/triangle pars/##1}}%
    \edef\lstsides{"a","b","c"}%
    \edef\lstangles{"A","B","C"}%
    \def\tmpundef{undef}%
    \edef\temp{\pv{a}}%
    \ifx\temp\tmpundef
     \edef\nsides{0}%
    \else
     \edef\nsides{1}%
     \edef\firstside{0}%
    \fi
    \edef\temp{\pv{b}}%
    \ifx\temp\tmpundef
    \else
     \edef\nsides{\the\numexpr\nsides+1}%
     \ifnum\nsides=1
      \edef\firstside{1}%
     \else
      \edef\secondside{1}%
     \fi
    \fi
    \edef\temp{\pv{c}}%
    \ifx\temp\tmpundef
    \else
     \edef\nsides{\the\numexpr\nsides+1}%
     \ifnum\nsides=1
      \edef\firstside{2}%
     \else
      \ifcase\nsides
       \or
        \edef\firstside{2}%
       \or
        \edef\secondside{2}%
       \or
        \edef\thirdside{c}%
      \fi 
     \fi
    \fi
    \edef\temp{\pv{A}}%
    \ifx\temp\tmpundef
     \edef\nangles{0}%
    \else
     \edef\nangles{1}%
     \edef\firstangle{0}%
    \fi
    \edef\temp{\pv{B}}%
    \ifx\temp\tmpundef
    \else
     \edef\nangles{\the\numexpr\nangles+1}%
     \ifnum\nangles=1
      \edef\firstangle{1}%
     \else
      \edef\secondangle{1}%
     \fi
    \fi
    \edef\temp{\pv{C}}%
    \ifx\temp\tmpundef
    \else
     \edef\nangles{\the\numexpr\nangles+1}%
     \ifcase\nangles
     \or
      \edef\firstangle{2}%
     \or
      \edef\secondangle{2}%
     \or
      \edef\thirdangle{2}%
     \fi     
    \fi
    \ifnum\numexpr\nangles+\nsides=3 % the number of input parameters is fine
     \ifcase\nsides
      \message{You need to specify at least one side.^^J}
     \or % one side and two angles
      \pgfmathsetmacro{\mysidei}{{\lstsides}[\firstside]}%
      \pgfmathsetmacro{\myanglei}{{\lstangles}[\firstangle]}%
      \pgfmathsetmacro{\myangleii}{{\lstangles}[\secondangle]}%
      \pgfmathtruncatemacro{\thirdangle}{Mod(3-\firstangle-\secondangle,3)}%
      \pgfmathsetmacro{\myangleiii}{{\lstangles}[\thirdangle]}%
      \pgfmathtruncatemacro{\itest}{(\firstside==\firstangle)||(\firstside==\secondangle)}%
      \ifnum\itest=0 % both angles involve known side
        \draw[pic actions] (0,0) 
            coordinate[label=below:$\pv{\myangleii}$] (-B) 
         -- node[midway,auto]{$\mysidei=\pv{\mysidei}$} 
         (\pv{a},0) coordinate (-C) 
         --
          (intersection cs:first line={(-B)--($(-B)+({\pv{\myangleii}}:1)$)},
          second line={(-C)--($(-C)+({-180+\pv{\myanglei}}:1)$)})
          coordinate (-A) -- cycle;   
      \else % one angle is away from the known side
       \ifnum\firstside=\firstangle
        \draw[pic actions] (0,0) 
         coordinate[label=below:$\myangleii$] (-\myangleii) 
         -- node[midway,auto]{$\mysidei=\pv{\mysidei}$} 
         (\pv{a},0) coordinate[label=below:$\myangleiii$] (-\myangleiii) 
         --
          (intersection cs:first line={(-\myangleii)--($(-\myangleii)+({\pv{\myangleii}}:1)$)},
          second line={(-\myangleiii)--($(-\myangleiii)+({-180+\pv{\myanglei}+\pv{\myangleii}}:1)$)})
          coordinate[label=above:$\myanglei$] (-\myanglei) -- cycle
          ($(-\myangleii)+(0:\pv{r})$)arc[start angle=0,end angle=\pv{\myangleii},radius=\pv{r}]
          ($(-\myanglei)+(180+\pv{\myangleii}:\pv{r})$)
          arc[start angle=180+\pv{\myangleii},end angle=180+\pv{\myanglei}+\pv{\myangleii},radius=\pv{r}]
          ;
       \else
        \draw[pic actions] (0,0) 
         coordinate[label=below:$\myanglei$] (-\myanglei) 
         -- node[midway,auto]{\mysidei} 
         (\pv{a},0) coordinate[label=below:$\myangleiii$] (-\myangleiii) 
         --
          (intersection cs:first line={(-\myanglei)--($(-\myanglei)+({\pv{\myanglei}}:1)$)},
          second line={(-\myangleiii)--($(-\myangleiii)+({-180+\pv{\myanglei}+\pv{\myangleii}}:1)$)})
          coordinate[label=above:$\myangleii$] (-\myangleii) -- cycle
          ($(-\myanglei)+(0:\pv{r})$)arc[start angle=0,end angle=\pv{\myanglei},radius=\pv{r}]
          ($(-\myangleii)+(180+\pv{\myanglei}:\pv{r})$)
          arc[start angle=180+\pv{\myanglei},end angle=180+\pv{\myanglei}+\pv{\myangleii},radius=\pv{r}]
          ;
       \fi    
      \fi
     \or % two sides and one angle
      \pgfmathsetmacro{\mysidei}{{\lstsides}[\firstside]}%
      \pgfmathsetmacro{\mysideii}{{\lstsides}[\secondside]}%
      \pgfmathsetmacro{\myanglei}{{\lstangles}[\firstangle]}%
      \pgfmathtruncatemacro{\thirdside}{Mod(3-\firstside-\secondside,3)}%
      \pgfmathsetmacro{\mysideiii}{{\lstsides}[\thirdside]}%
      \pgfmathsetmacro{\myangleii}{{\lstangles}[\secondside]}%
      \pgfmathsetmacro{\myangleiii}{{\lstangles}[\thirdside]}%
      \pgfmathtruncatemacro{\itest}{(\firstside==\firstangle)||(\secondside==\firstangle)}%
      \ifnum\itest=0 % both sides attach to the angle
       \pgfmathsetmacro{\myangleii}{{\lstangles}[\firstside]}%
       \pgfmathsetmacro{\myangleiii}{{\lstangles}[\secondside]}%
       \draw[pic actions] (\pv{\myanglei}:\pv{\mysidei}) 
            coordinate[label=above:$\myangleiii$] (-\myangleiii)
        --   node[midway,auto]{$\mysidei=\pv{\mysidei}$} 
        (0,0) coordinate[label=below:$\myanglei$] (-\myanglei) 
        --  node[midway,auto]{$\mysideii=\pv{\mysideii}$}  
        (\pv{\mysideii},0) coordinate[label=below:$\myangleii$] (-\myangleii)
       --  cycle
       (\pv{r},0) arc[start angle=0,end angle=\pv{\myanglei},radius=\pv{r}];
      \else
       \pgfmathsetmacro{\mya}{max(\pv{\mysidei},\pv{\mysideii})}%
       \pgfmathsetmacro{\myb}{min(\pv{\mysidei},\pv{\mysideii})}%
       \pgfmathsetmacro{\myc}{\myb*cos(\pv{\myanglei})%
        +sqrt(\mya*\mya-pow(\myb*sin(\pv{\myanglei}),2)}%
       \ifnum\firstside=\firstangle
        \draw[pic actions] (\pv{\myanglei}:\myc) 
             coordinate[label=above:$\myangleii$] (-\myangleii)
          --  (0,0) coordinate[label=below:$\myanglei$] (-\myanglei) 
          --  node[midway,auto]{$\mysideii=\pv{\mysideii}$}  
         (\pv{\mysideii},0) coordinate[label=below:$\myangleiii$] (-\myangleiii)
        --  node[midway,auto]{$\mysidei=\pv{\mysidei}$}  cycle
        (\pv{r},0) arc[start angle=0,end angle=\pv{\myanglei},radius=\pv{r}];
       \else
        \pgfmathsetmacro{\myangleii}{{\lstangles}[\thirdside]}%
        \pgfmathsetmacro{\myangleiii}{{\lstangles}[\firstside]}%
        \draw[pic actions] (\pv{\myanglei}:\myc) 
             coordinate[label=above:$\myangleiii$] (-\myangleiii)
          --  (0,0) coordinate[label=below:$\myanglei$] (-\myanglei) 
          --  node[midway,auto]{$\mysidei=\pv{\mysidei}$}  
         (\pv{\mysidei},0) coordinate[label=below:$\myangleii$] (-\myangleii)
        --  node[midway,auto]{$\mysideii=\pv{\mysideii}$}  cycle
        (\pv{r},0) arc[start angle=0,end angle=\pv{\myanglei},radius=\pv{r}];
       \fi
      \fi
     \or %three sides
      %\typeout{3 sides}
      \pgfmathsetmacro{\mymax}{max(\pv{a},\pv{b},\pv{c})}%
      \pgfmathtruncatemacro{\itest}{sign(2*\mymax-\pv{a}-\pv{b}-\pv{c})}%
      \ifnum\itest<1
       \draw[pic actions] (0,0) coordinate[label=below:$B$] (-B) 
        -- node[midway,auto]{$a=\pv{a}$} 
        (\pv{a},0) coordinate[label=below:$C$] (-C) 
         -- node[midway,auto]{$b=\pv{b}$}
        (intersection cs:first line={(-B)--($(-B)+({cosinelaw(\pv{a},\pv{c},\pv{b})}:1)$)},
         second line={(-C)--($(-C)+({-cosinelaw(\pv{a},\pv{b},\pv{c})}:1)$)})
         coordinate[label=above:$A$] (-A) -- 
         node[midway,auto]{$c=\pv{c}$} cycle;
      \else
       \message{a=\pv{a},b=\pv{b},c=\pv{c} is not consistent since one side is
        longer than the sum of two other sides.^^J}
      \fi    
     \fi
    \else
     \message{Incorrect input. You need to specify three parameters.^^J}     
    \fi
    }},
  declare function={cosinelaw(\a,\b,\c)=acos((\a*\a+\b*\b-\c*\c)/(2*\a*\b));},
  triangle pars/.cd,
  A/.initial=undef,B/.initial=undef,C/.initial=undef,% angles
  a/.initial=undef,b/.initial=undef,c/.initial=undef,% sides
  r/.initial=1%radius of angles
  }
\begin{document}
\subsection*{Specify triangle by its three sides}
\begin{tikzpicture}
  \pic{triangle={a=5,b=4,c=3}};
\end{tikzpicture}

\subsection*{Specify triangle by two sides and one angle}
\begin{tikzpicture}
  \pic{triangle={a=5,b=4,A=40}};
\end{tikzpicture}

\begin{tikzpicture}
  \pic{triangle={a=5,b=4,B=40}};
\end{tikzpicture}

\begin{tikzpicture}
  \pic{triangle={a=5,b=4,C=40}};
\end{tikzpicture}


\subsection*{Specify triangle by one side and two angles}
\begin{tikzpicture}
  \pic{triangle={a=5,A=60,B=70}};
\end{tikzpicture}

\begin{tikzpicture}
  \pic{triangle={a=5,A=60,C=70}};
\end{tikzpicture}

\end{document}

在此处输入图片描述

在此处输入图片描述

答案4

所有可能的解决方案(我认为):

\documentclass{article}
\usepackage{booktabs}
\usepackage{isonums} %for comma in number instead of point
\usepackage{tikz}
\usetikzlibrary{math,calc,angles,backgrounds}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\sideLabel}[3]{\node at ($($#1!0.5!#2$)!3mm!90:#2$) {$#3$};}
%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\sideMark}[3]{\node[red] at ($($#1!0.5!#2$)!3mm!90:#2$) {$#3$};}
%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\angleMark}[4]{
\coordinate (A) at #1;
\coordinate (B) at #2;
\coordinate (C) at #3;
\begin{scope}[on background layer]
\path pic[red,pic text=$#4$,draw,angle eccentricity=1.6]{angle=C--B--A};
\end{scope}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\angleLabel}[4]{
\coordinate (A) at #1;
\coordinate (B) at #2;
\coordinate (C) at #3;
\path pic[pic text=$#4^\circ$,draw,angle eccentricity=1.6]{angle=C--B--A};
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\solutions}[1]{
\pgfkeys{/pgf/number format/precision={2}}
\node[anchor=north west,red] at (current bounding box.south west){[#1]};}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\SSS}[3]{%
\tikzmath{%
\angleA = acos((#2^2 + #3^2 -(#1^2))/(2*#2*#3));
\angleB = acos((#1^2 + #3^2 -(#2^2))/(2*#1*#3));
\angleC = 180 - \angleA - \angleB;
}
% draw triangle
\draw (0,0) -- (\angleB:#3) -- (#1,0) -- cycle;
% labels
\sideLabel{(0,0)}{(\angleB:#3)}{#3}
\sideLabel{(\angleB:#3)}{(#1,0)}{#2}
\sideLabel{(#1,0)}{(0,0)}{#1}
%unknows
\angleMark{(#1,0)}{(\angleB:#3)}{(0,0)}{A}
\angleMark{(\angleB:#3)}{(0,0)}{(#1,0)}{B}
\angleMark{(0,0)}{(#1,0)}{(\angleB:#3)}{C}
% Solutions
\solutions{$A=\pgfmathprintnumber{\angleA}^\circ$, $B=\pgfmathprintnumber{\angleB}^\circ$, $C=\pgfmathprintnumber{\angleC}^\circ$};
}
%%%%%%%%%%%%%%%%%%%
\newcommand{\SAS}[3]{%
\tikzmath{%
\ThirdSide = sqrt(#1^2 + #3^2 - 2*#1*#3*cos(#2));
\AngleOppositeFirstSide = acos((#3^2 + \ThirdSide^2 -(#1^2))/(2*#3*\ThirdSide));
\AngleOppositeSecondSide = acos((#1^2 + \ThirdSide^2 -(#3^2))/(2*#1*\ThirdSide));
}
%draw triangle
\draw (0,0) -- (\AngleOppositeSecondSide:\ThirdSide) -- (#1,0) -- cycle;
%labels
\sideLabel{(\AngleOppositeSecondSide:\ThirdSide)}{(#1,0)}{#3}
\sideLabel{(#1,0)}{(0,0)}{#1}
\angleLabel{(0,0)}{(#1,0)}{(\AngleOppositeSecondSide:\ThirdSide)}{#2}
% unknows
\sideMark{(0,0)}{(\AngleOppositeSecondSide:\ThirdSide)}{a}
\angleMark{(#1,0)}{(\AngleOppositeSecondSide:\ThirdSide)}{(0,0)}{A}
\angleMark{(\AngleOppositeSecondSide:\ThirdSide)}{(0,0)}{(#1,0)}{B}
% solutions
\solutions{$a=\pgfmathprintnumber{\ThirdSide}$, $A=\pgfmathprintnumber{\AngleOppositeFirstSide}^\circ$, $B=\pgfmathprintnumber{\AngleOppositeSecondSide}^\circ$}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\ASA}[3]{%
\tikzmath{%
\ThirdAngle = 180 - #1 - #3;
\SideOppositeFirstAngle =   #2*sin(#1)/sin(\ThirdAngle);
\SideOppositeSecondAngle =  #2*sin(#3)/sin(\ThirdAngle);
}
% draw triangle
\draw (0,0) -- (#1:\SideOppositeSecondAngle) -- (#2,0) -- cycle;
% labels
\angleLabel{(#1:\SideOppositeSecondAngle)}{(0,0)}{(#2,0)}{#1}
\sideLabel{(#2,0)}{(0,0)}{#2}
\angleLabel{(0,0)}{(#2,0)}{(#1:\SideOppositeSecondAngle)}{#3}
% unknows
\sideMark{(#1:\SideOppositeSecondAngle)}{(#2,0)}{a}
\sideMark{(0,0)}{(#1:\SideOppositeSecondAngle)}{b}
\angleMark{(#2,0)}{(#1:\SideOppositeSecondAngle)}{(0,0)}{A}
% solutions
\solutions{$a=\pgfmathprintnumber{\SideOppositeFirstAngle}$, $b=\pgfmathprintnumber{\SideOppositeSecondAngle}$, $A=\pgfmathprintnumber{\ThirdAngle}^\circ$}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\AAS}[3]{%
\tikzmath{%
\ThirdAngle = 180 - #1 - #2;
\SideOppositeSecondAngle =  #3*sin(#2)/sin(#1);
\SideOppositeThirdAngle =   #3*sin(\ThirdAngle)/sin(#1);
}
% draw triangle
\draw (0,0) -- (#1:\SideOppositeSecondAngle) -- (\SideOppositeThirdAngle,0) -- cycle;
% labels
\angleLabel{(#1:\SideOppositeSecondAngle)}{(0,0)}{(\SideOppositeThirdAngle,0)}{#1}
\angleLabel{(0,0)}{(\SideOppositeThirdAngle,0)}{(#1:\SideOppositeSecondAngle)}{#2}
\sideLabel{(#1:\SideOppositeSecondAngle)}{(\SideOppositeThirdAngle,0)}{#3}
%unknows
\sideMark{(\SideOppositeThirdAngle,0)}{(0,0)}{a}
\sideMark{(0,0)}{(#1:\SideOppositeSecondAngle)}{b}
\angleMark{(\SideOppositeThirdAngle,0)}{(#1:\SideOppositeSecondAngle)}{(0,0)}{A}
%solutions
\solutions{$a=\pgfmathprintnumber{\SideOppositeThirdAngle}$, $b=\pgfmathprintnumber{\SideOppositeSecondAngle}$, $A=\pgfmathprintnumber{\ThirdAngle}^\circ$}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\SsA}[3]{%
\tikzmath{%
\AngleOppositeSecondSide = asin((#2/#1)*sin(#3));
\AngleOppositeThirdSide = 180 - #3 -\AngleOppositeSecondSide;
\ThirdSide = #1*sin(\AngleOppositeThirdSide)/sin(#3);
}
%draw triangle
\draw (0,0) -- (\AngleOppositeSecondSide:\ThirdSide) -- (#1,0) -- cycle;
%labels
\sideLabel{(#1,0)}{(0,0)}{#1}
\sideLabel{(\AngleOppositeSecondSide:\ThirdSide)}{(#1,0)}{#2}
\angleLabel{(#1,0)}{(\AngleOppositeSecondSide:\ThirdSide)}{(0,0)}{#3}
%unknows
\sideMark{(0,0)}{(\AngleOppositeSecondSide:\ThirdSide)}{a}
\angleMark{(\AngleOppositeSecondSide:\ThirdSide)}{(0,0)}{(#1,0)}{A}
\angleMark{(0,0)}{(#1,0)}{(\AngleOppositeSecondSide:\ThirdSide)}{B}
%solutions
\solutions{$a=\pgfmathprintnumber{\ThirdSide}$, $A=\pgfmathprintnumber{\AngleOppositeSecondSide}^\circ$, $B=\pgfmathprintnumber{\AngleOppositeThirdSide}^\circ$}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%First Solution
\newcommand{\sSAfirst}[3]{%
\tikzmath{%
\AngleOppositeSecondSide = asin((#2/#1)*sin(#3));
\AngleOppositeThirdSide = 180 - #3 -\AngleOppositeSecondSide;
\ThirdSide = #1*sin(\AngleOppositeThirdSide)/sin(#3);
}
% draw triangle
\draw (0,0) -- (\AngleOppositeSecondSide:\ThirdSide) -- (#1,0) -- cycle;
% labels
\sideLabel{(#1,0)}{(0,0)}{#1}
\sideLabel{(\AngleOppositeSecondSide:\ThirdSide)}{(#1,0)}{#2}
\angleLabel{(#1,0)}{(\AngleOppositeSecondSide:\ThirdSide)}{(0,0)}{#3}
% unknows
\sideMark{(0,0)}{(\AngleOppositeSecondSide:\ThirdSide)}{a}
\angleMark{(\AngleOppositeSecondSide:\ThirdSide)}{(0,0)}{(#1,0)}{A}
\angleMark{(0,0)}{(#1,0)}{(\AngleOppositeSecondSide:\ThirdSide)}{B}
% solutions
\solutions{$a=\pgfmathprintnumber{\ThirdSide}$, $A=\pgfmathprintnumber{\AngleOppositeSecondSide}^\circ$, $B=\pgfmathprintnumber{\AngleOppositeThirdSide}^\circ$}
}
%%%Second Solution
\newcommand{\sSAsecond}[3]{%
\tikzmath{%
\AngleOppositeSecondSide = 180 - asin((#2/#1)*sin(#3));
\AngleOppositeThirdSide = 180 - #3 -\AngleOppositeSecondSide;
\ThirdSide = #1*sin(\AngleOppositeThirdSide)/sin(#3);
}
% draw triangle
\draw (0,0) -- (\AngleOppositeSecondSide:\ThirdSide) -- (#1,0) -- cycle;
% labels
\sideLabel{(#1,0)}{(0,0)}{#1}
\sideLabel{(\AngleOppositeSecondSide:\ThirdSide)}{(#1,0)}{#2}
\angleLabel{(#1,0)}{(\AngleOppositeSecondSide:\ThirdSide)}{(0,0)}{#3}
% unknows
\sideMark{(0,0)}{(\AngleOppositeSecondSide:\ThirdSide)}{a}
\angleMark{(\AngleOppositeSecondSide:\ThirdSide)}{(0,0)}{(#1,0)}{A}
\angleMark{(0,0)}{(#1,0)}{(\AngleOppositeSecondSide:\ThirdSide)}{B}
% solutions
\solutions{$a=\pgfmathprintnumber{\ThirdSide}$, $A=\pgfmathprintnumber{\AngleOppositeSecondSide}^\circ$, $B=\pgfmathprintnumber{\AngleOppositeThirdSide}^\circ$}
}
\begin{document}
\pagestyle{empty}
\section{SSS} %the sum of any two sides must less then the third side.
\tikz{\SSS{3}{4}{5}}

\section{SAS} %the angle must be less than 180
\tikz{\SAS{5}{40}{4}}

\section{ASA} %the sum of two angle must be less then 180 
\tikz{\ASA{30}{5}{40}}

\section{AAS} %the sum of two angle must be less then 180 
\tikz{\AAS{30}{40}{5}}

\section{SsA} %S must be greater or equal to s. If S is equal to s (isoscele triangle) the angle must be less then 90
\tikz{\SsA{5}{4}{40}}

\section{sSA} %S must be greater or equal to s. In this case it's possible to draw two different triangles. 
%If S is equal to s (isoscele triangle) the triangle is unique and the same as SsA.
%The angle A must be less then arcsin(s/S)
\begin{tabular}{ll}
\tikz{\sSAfirst{4}{5}{40}}&
\tikz{\sSAsecond{4}{5}{40}}\\
\end{tabular}
\end{document}

构造一个由三个元素组成的三角形-1 在此处输入图片描述

相关内容