输入随机数但仍使三角形工作

输入随机数但仍使三角形工作
\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}

代码量太大了,我很抱歉!但我想知道是否有办法为工作表创建真正适用于三角形的随机数。我可以创建工作表和随机数,但有时它们现在不起作用,任何帮助都将不胜感激。

相关内容