将弧度转换为度、分和秒 [英] Convert radians to degrees, minutes, and seconds

查看:86
本文介绍了将弧度转换为度、分和秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种将小数转换为 C 中的度数的方法.例如,C 中的 asin() 函数返回一个十进制数,但我需要该数字以度°分'秒为单位.

I am looking on a way to convert decimals to degrees in C. For instance, the asin() function in C returns a decimal number but I need that number to be in degrees ° minutes ' seconds ".

例如1.5 将是 1°30'0"

e.g. 1.5 would be 1°30'0"

推荐答案

asin 函数返回弧度.一个圆有 2 个 π 弧度.

The asin function returns radians. There are 2 π radians in a circle.

一个圆有 360 度,一个度有 60 分钟,一分钟有 60 秒.所以一圈有360*60*60秒.

There are 360 degrees in a circle, 60 minutes in a degree, and 60 seconds in a minute. So there are 360*60*60 seconds in a circle.

double radians = asin(opposite / hypotenuse);
int totalSeconds = (int)round(radians * 360 * 60 * 60 / (2 * M_PI));
int seconds = totalSeconds % 60;
int minutes = (totalSeconds / 60) % 60;
int degrees = totalSeconds / (60 * 60);

这篇关于将弧度转换为度、分和秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆