如何自动将计算的角度转换为度分秒

如何自动将计算的角度转换为度分秒

我想为几何学的一部分制作一组练习。在这个文档中,我可以更改三角形的长度。它计算角度。但我想要以度分秒为单位的角度。我该怎么做?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\usepackage{pgf,tikz,tkz-tab,tkz-euclide,pgfplots,tkz-fct,tikz-3dplot,rotating}
\usetikzlibrary{angles,arrows,arrows.meta,backgrounds, calc,decorations,decorations.markings,decorations.pathmorphing, decorations.text, fit,intersections,patterns,positioning,shapes,shadows,shapes.misc,through,tikzmark}

\begin{document}
\begin{tikzpicture}[scale=2]
%% names of the corners
\newcommand\HR{X}
\newcommand\HS{Y} 
\newcommand\HSS{Z} 
%% length of the sides
\pgfmathsetmacro{\RZ}{3}
\pgfmathsetmacro{\RZZ}{4.4}
\pgfmathsetmacro{\SZ}{sqrt(pow(\RZ,2)+pow(\RZZ,2))}

%% name of the sides
\newcommand\ZZ{$x=\num[round-mode=places,round-precision=2]{\SZ}$} 
\newcommand\ZZZ{$y=?$} %% Geef hier de naam + schuine zijde
\newcommand\Z{$z=\num{\RZ}$} % Geef hier de naam + lengte korte rechthoekzijde
% start
\tkzDefPoints{1/1/\HR};
% other points
 \tkzDefShiftPoint[\HR](0:\RZ){\HS};
 \tkzDefShiftPoint[\HR](90:\RZZ){\HSS};
% label sides
\tkzLabelSegment[sloped,below](\HR,\HS){\Z};
\tkzLabelSegment[sloped,above](\HS,\HSS){\ZZ};
\tkzLabelSegment[sloped](\HR,\HSS){\ZZZ};
% labels
\tkzDrawPoints[fill=black](\HR,\HS,\HSS);
\tkzLabelPoints[above](\HSS);
\tkzLabelPoints[below](\HR,\HS);
\tkzDrawPolygon[thick](\HR,\HS,\HSS);
\tkzMarkRightAngles[size=.5](\HS,\HR,\HSS);
\tkzFindAngle (\HSS,\HS,\HR)  \tkzGetAngle{hoekY}
 \FPround\hoekY\hoekY{0} %
\tkzLabelAngle(\HSS,\HS,\HR) {\ang{\hoekY}};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

在欧几里得几何中,所有角度都在0到180度之间。经度分为东和西,而不是正和负。

\documentclass{article}
\usepackage{tikz}% includes pgfmath

\newcommand{\ancient}[1]% #1 = angle in degrees (text with decimals)
{\bgroup% use local names
  \pgfmathsetmacro{\tempb}{mod(#1,180)}% angle between -180 and 180
  \pgfmathsetmacro{\tempa}{ifthenelse(\tempb>0, \tempb, 360+\tempb)}% angle between 0 and 360
  \pgfmathsetmacro{\degrees}{int(\tempa)}%
  \pgfmathsetmacro{\tempb}{(\tempa-\degrees)*60}%
  \pgfmathsetmacro{\minutes}{(int(\tempb)}%
  \pgfmathsetmacro{\seconds}{int((\tempb-\minutes)*60}%
  {\degrees} degrees, {\minutes} minutes, {\seconds} seconds
\egroup}

\begin{document}
  \ancient{5.33}
  
  \ancient{-400}
\end{document}

答案2

感谢@John Kormylo在此处输入图片描述

    \documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\usepackage{pgf,tikz,tkz-tab,tkz-euclide,pgfplots,tkz-fct,tikz-3dplot,rotating} 
\usetikzlibrary{angles,arrows,arrows.meta,backgrounds,calc,decorations,decorations.markings,decorations.pathmorphing, decorations.text,fit,intersections,patterns,positioning,shapes,shadows,shapes.misc,through,tikzmark}

\newcommand{\ancient}[1]% #1 = angle in degrees (text with decimals)
{\bgroup% use local names
  \pgfmathsetmacro{\tempa}{mod(ifthenelse(#1>0, #1, 360+#1),360)}% angle between 0 and 360
  \pgfmathsetmacro{\degrees}{int(\tempa)}%
  \pgfmathsetmacro{\tempb}{(\tempa-\degrees)*60}%
  \pgfmathsetmacro{\minutes}{(int(\tempb)}% \minutes already used
  \pgfmathsetmacro{\seconds}{int((\tempb-\minutes)*60}%
  \ang{{\degrees};{\minutes};{\seconds}}
    \egroup}


 \begin{document}
\begin{tikzpicture}[scale=2]
%% names of the corners
\newcommand\HR{X}
\newcommand\HS{Y} 
\newcommand\HSS{Z} 
%% length of the sides
\pgfmathsetmacro{\RZ}{3}
\pgfmathsetmacro{\RZZ}{4.4}
\pgfmathsetmacro{\SZ}{sqrt(pow(\RZ,2)+pow(\RZZ,2))}

%% name of the sides
\newcommand\ZZ{$x=\num[round-mode=places,round-precision=2]{\SZ}$} 
\newcommand\ZZZ{$y=?$} %% Geef hier de naam + schuine zijde
\newcommand\Z{$z=\num{\RZ}$} % Geef hier de naam + lengte korte rechthoekzijde
% start
\tkzDefPoints{1/1/\HR};
% other points
 \tkzDefShiftPoint[\HR](0:\RZ){\HS};
 \tkzDefShiftPoint[\HR](90:\RZZ){\HSS};
% label sides
\tkzLabelSegment[sloped,below](\HR,\HS){\Z};
\tkzLabelSegment[sloped,above](\HS,\HSS){\ZZ};
\tkzLabelSegment[sloped](\HR,\HSS){\ZZZ};
% labels
\tkzDrawPoints[fill=black](\HR,\HS,\HSS);
\tkzLabelPoints[above](\HSS);
\tkzLabelPoints[below](\HR,\HS);
\tkzDrawPolygon[thick](\HR,\HS,\HSS);
\tkzMarkRightAngles[size=.5](\HS,\HR,\HSS);
\tkzFindAngle (\HSS,\HS,\HR)  \tkzGetAngle{hoekY}
 \FPround\hoekY\hoekY{5} %
\tkzLabelAngle(\HSS,\HS,\HR) {\ancient{\hoekY}};
\end{tikzpicture}
\end{document}

相关内容