\tkzGetAngle 奇怪的行为

\tkzGetAngle 奇怪的行为

我想画几个不同的三角形 ABC,并标记角度,并在其中写上角度值。感谢另一个问题的回答,我设法得到了以下代码:

\documentclass{article}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all} %% om allerhande objecten te gebruiken zoals gradenboog...
\usetikzlibrary{calc,intersections,through,backgrounds,snakes}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{statistics}


\begin{document}

\makeatletter
\newcommand\ddToddmmss[1]{%
\pgfmathtruncatemacro\deg@tmp{#1}%
\pgfmathsetmacro\min@tmp{(#1-\deg@tmp)*60}%
\pgfmathtruncatemacro\Min@tmp{\min@tmp}
\pgfmathtruncatemacro\sec@tmp{(\min@tmp-floor(\min@tmp))*60}%
\ensuremath{\deg@tmp^\circ \Min@tmp ' \sec@tmp ''}}
\makeatother


\begin{tikzpicture}
\tkzInit[ymin=0,ymax=9,xmin=0,xmax=15]
\tkzClip
\tkzGrid
\tkzDefPoints{1/3/A, 7/8/B, 12/1/C}
\tkzDrawPolygon(A,B,C) \tkzDrawPoints(A,B,C) \tkzLabelPoints(A,B,C)

\tkzMarkAngle[fill= red,size=1.5cm, opacity=.4](C,A,B);
\tkzFindAngle(C,A,B) \tkzGetAngle{angleCAB};
%\FPround\angleBAC\angleCAB{2}
\tkzLabelAngle[pos = 2.3](C,A,B){\ddToddmmss{\angleCAB}};  

\tkzMarkAngle[fill= red,size=1.5cm, opacity=.4](A,B,C);
\tkzFindAngle(A,B,C) \tkzGetAngle{angleABC};
%\FPround\angleABC\angleABC{2}
\tkzLabelAngle[pos = 2.3](A,B,C){\ddToddmmss{\angleABC}};

\tkzMarkAngle[fill= red,size=1.5cm, opacity=.4](B,C,A);
\tkzFindAngle(B,C,A) \tkzGetAngle{angleBCA};
%\FPround\angleBCA\angleBCA{2}
\tkzLabelAngle[pos = 2.3](B,C,A){\ddToddmmss{\angleBCA}};
\end{tikzpicture}


\begin{tikzpicture}
\tkzInit[ymin=0,ymax=9,xmin=0,xmax=15]
\tkzClip
\tkzGrid
\tkzDefPoints{1/3/A, 7/8/B, 12/5/C}
\tkzDrawPolygon(A,B,C) \tkzDrawPoints(A,B,C) \tkzLabelPoints(A,B,C)

\tkzMarkAngle[fill= red,size=1.5cm, opacity=.4](C,A,B);
\tkzFindAngle(C,A,B) \tkzGetAngle{angleCAB};
%\FPround\angleBAC\angleCAB{2}
\tkzLabelAngle[pos = 2.3](C,A,B){\ddToddmmss{\angleCAB}};  

\tkzMarkAngle[fill= red,size=1.5cm, opacity=.4](A,B,C);
\tkzFindAngle(A,B,C) \tkzGetAngle{angleABC};
%\FPround\angleABC\angleABC{2}
\tkzLabelAngle[pos = 2.3](A,B,C){\ddToddmmss{\angleABC}};

\tkzMarkAngle[fill= red,size=1.5cm, opacity=.4](B,C,A);
\tkzFindAngle(B,C,A) \tkzGetAngle{angleBCA};
%\FPround\angleBCA\angleBCA{2}
\tkzLabelAngle[pos = 2.3](B,C,A){\ddToddmmss{\angleBCA}};
\end{tikzpicture}

\end{document}

三角形 1 和 2

问题是,在版本 2 中,点 C 高于点 A,他采取了错误的角度。

有什么建议么?

答案1

如果您查看\tkzFindAngle中的定义tkz-obj-angles.tex,您会发现它使用非常简单的方法来计算角度。

\def\tkzFindAngle(#1,#2,#3){%
\begingroup
      \tkzFindSlopeAngle(#2,#1)\tkzGetAngle{tkz@FirstAngle}
      \tkzFindSlopeAngle(#2,#3)\tkzGetAngle{tkz@SecondAngle}
      \FPadd\tkz@Angle{\tkz@SecondAngle}{-\tkz@FirstAngle}
     \global\let\tkzAngleResult\tkz@Angle
\endgroup
}

同样,可以\tkz@LabelAngle很简单地计算将标签放在哪里。

\def\tkz@LabelAngle[#1](#2,#3,#4)#5{%
\begingroup
\pgfkeys{tkzlabelangle/.cd,
         dist  = 1}
\pgfqkeys{/tkzlabelangle}{#1}
\tkzFindSlopeAngle(#3,#2)\tkzGetAngle{tkz@dirOne}
\tkzFindSlopeAngle(#3,#4)\tkzGetAngle{tkz@dirTwo}
\FPeval\labelAngle{( \tkz@dirOne +\tkz@dirTwo)/2}
\path (#3) --+(\labelAngle:\labeldist) node[/tkzmkangle/.cd,#1] {#5};
\endgroup
}

\tkzMarkAngle使用更复杂的计算来\tkzDrawArcRAN标记角度。

\def\tkzDrawArcRAN[#1](#2,#3)(#4,#5){%
 \begingroup
 \pgfmathparse{#4}\edef\tkz@FirstAngle{\pgfmathresult}%
 \pgfmathparse{#5}\edef\tkz@SecondAngle{\pgfmathresult}%
  \pgfmathgreaterthan{\tkz@FirstAngle}{0}
  \ifdim\pgfmathresult pt=1 pt\relax%
    \pgfmathgreaterthan{\tkz@FirstAngle}{\tkz@SecondAngle}
    \ifdim\pgfmathresult pt=1 pt\relax%
     \pgfmathsubtract{\tkz@FirstAngle}{360}
     \edef\tkz@FirstAngle{\pgfmathresult}%
 \fi
 \else
     \pgfmathgreaterthan{\tkz@FirstAngle}{\tkz@SecondAngle}
    \ifdim\pgfmathresult pt=1 pt\relax%
     \pgfmathadd{\tkz@SecondAngle}{360}
     \edef\tkz@SecondAngle{\pgfmathresult}%
 \fi
 \fi
     \draw[shift = {(#2)},/drawarc/.cd,#1]%
       (\tkz@FirstAngle:#3) arc (\tkz@FirstAngle:\tkz@SecondAngle:#3);
\endgroup
}

使用相同的角度标准化可能\tkzMarkAngle就是您所追求的。

\makeatletter
\def\tkzFindAngle(#1,#2,#3){%
\begingroup
  \tkzFindSlopeAngle(#2,#1)\tkzGetAngle{tkz@FirstAngle}
  \tkzFindSlopeAngle(#2,#3)\tkzGetAngle{tkz@SecondAngle}
  \my@NormalizeAngle(\tkz@FirstAngle,\tkz@SecondAngle)
  \FPadd\tkz@Angle{\my@SecondAngle}{-\my@FirstAngle}
  \global\let\tkzAngleResult\tkz@Angle
\endgroup
}

\def\tkz@LabelAngle[#1](#2,#3,#4)#5{%
\begingroup
  \pgfkeys{tkzlabelangle/.cd,dist=1}
  \pgfqkeys{/tkzlabelangle}{#1}
  \tkzFindSlopeAngle(#3,#2)\tkzGetAngle{tkz@dirOne}
  \tkzFindSlopeAngle(#3,#4)\tkzGetAngle{tkz@dirTwo}
  \my@NormalizeAngle(\tkz@dirOne,\tkz@dirTwo)
  \FPeval\labelAngle{(\my@FirstAngle +\my@SecondAngle)/2}
  \path (#3) --+(\labelAngle:\labeldist) node[/tkzmkangle/.cd,#1] {#5};
\endgroup
}

\def\my@NormalizeAngle(#1,#2){%
\begingroup
  \pgfmathparse{#1}\xdef\my@FirstAngle{\pgfmathresult}%
  \pgfmathparse{#2}\xdef\my@SecondAngle{\pgfmathresult}%
  \pgfmathgreaterthan{\my@FirstAngle}{0}
  \ifdim\pgfmathresult pt=1 pt\relax%
    \pgfmathgreaterthan{\my@FirstAngle}{\my@SecondAngle}
    \ifdim\pgfmathresult pt=1 pt\relax%
      \pgfmathsubtract{\my@FirstAngle}{360}
      \xdef\my@FirstAngle{\pgfmathresult}%
    \fi
  \else
    \pgfmathgreaterthan{\my@FirstAngle}{\my@SecondAngle}
    \ifdim\pgfmathresult pt=1 pt\relax%
      \pgfmathadd{\my@SecondAngle}{360}
      \xdef\my@SecondAngle{\pgfmathresult}%
    \fi
  \fi
\endgroup
}
\makeatother

在此处输入图片描述

相关内容