作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在编写一个程序来计算时针和分针、时针、分针和秒针之间的角度。
我写了我的代码,但无论我如何改变我的计算,我仍然无法得到本文想要的答案..
我用了双
//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/
我是一名优秀的程序员,十分优秀!