c - 时分秒针之间的角度

标签 c algorithm

我正在编写一个程序来计算时针和分针、时针、分针和秒针之间的角度。

我写了我的代码,但无论我如何改变我的计算,我仍然无法得到本文想要的答案..

我用了双

//I did this to calculate the minute angle precisely since I assume 
//the second hand is also moving and it affects 1degree when it moves to 60..
angleminute=((6.0*minutes)+((1/60.0)*seconds)); 

//Also this to calculate the hour angle, the normal formula is 0.5*minutes
//but i also added the "seconds/60" for more accuracy
anglehour=((30.0*hour12)+(0.5*((seconds/60)+minutes)))

anglesecond=(6.0*seconds) //this is to calculate the second hand angle...

现在,当我发现这些角度之间的差异时,我会得到不同的结果...

11:54:29 这是我的结果

Hour-minute= 32.52
Minute-second= 150.48
Second-hour=177.00

预期的结果是:

Hour-minute=30.34
Minute-second= 152.90
Second-hour=176.76

他是如何获得这些结果的?我也尝试过使用普通方法,但仍然无法获得相同的结果。公式很多但还是得不到相同的答案...

angleminute=6*minutes

anglehour=30*hour+0.5*minutes

anglesecond=6*seconds

最佳答案

您的angleminute 计算有误。它确实每分钟移动 6 度,但每秒是 1/60 分钟,因此它每秒移动 1/60 * 6 度,而不是 1/60 度。

另外,分钟小时是什么类型?如果是int,那么还有一个问题:在anglehour的计算中,(seconds/60)会被整除,并且将以 0 的形式出现。您需要 (seconds/60.0)

关于c - 时分秒针之间的角度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26387191/

相关文章:

c++ - 带有引号和反斜杠的 C/C++ 宏错误

c - 用于 OLED 屏幕的 Debian I2C 驱动程序不起作用。 [SSD1306]

iphone - NSPredicate 在内部使用任何搜索算法?

C++ 使这个 Djikstra 实现更快

python - 图节点中的 BFS

c - 如何在 C 中对指向结构的指针数组进行排序?

c++ - 允许任何进程发送退出消息

c - 当我们改变指针的内容时指针指向哪里?

c++ - 使用信号量的冒泡排序算法

c++ - 剪辑数字的最有效/优雅的方式?