gpt4 book ai didi

c - 时分秒针之间的角度

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:33:03 24 4
gpt4 key购买 nike

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

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

我用了双

//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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com