如何计算时针和分针之间的角度? [英] How do I calculate the angle between the hour and minutes hands?

查看:57
本文介绍了如何计算时针和分针之间的角度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解决此问题,但我仍在努力理解解决此问题的逻辑.

I'm trying to workout this problem, but I am still struggling to understand the logic to solve this problem.

hour degree = 360 / 12 = 30
minutes degree = 360 / 12 / 60 = 0.5

因此,据此,我认为我可以在python中编写以下函数:

So, according to this, I thought I could formulate the following function in python:

def clockangles(hour, min):
    return (hour * 30) + (min * 0.5)

对于小时,它似乎工作正常,因为它似乎具有1 = 1映射.但是目前至少存在一个问题.0分钟时,分针指向12.

For the hour, it works fine, as it appears to have a 1=1 mapping. But for the minute there is one problem at least. When it's 0 minutes, the minutes hand points to 12.

例如:

晚上7点:指针指向晚上7点,分钟指向12点

7pm: hands pointing to 7pm and minutes pointing to 12

如何正确计算分钟数?请帮助我理解公式.

How do I calculate the minutes properly? Please help me understand the formula.

例如,如果我在晚上7点调用上述函数,例如Clockangles(7,0),则得到值210.但是,根据

For example, if I call the function above with 7pm, e.g clockangles(7,0) I get the value 210. However, according this link the angle at 7:00 is 150

推荐答案

好的.您正在尝试找到两只手之间的角度.然后:

Okay. You are trying to find the angle between the two hands. Then this:

minutes degree = 360 / 12 / 60 = 0.5

仅是小时指针每分钟移动的度数.考虑一下-分针每小时运转360分钟.因此,完整的旋转仅需60分钟.分针为360/60 =每分钟6度.

Is just the number of degrees the hour hand moves per minute. Think about it - the minute hand travels a full 360 each hour. Therefore there are only 60 minutes in a full revolution. 360/60 = 6 degrees per minute for the minute hand.

因此,您需要找到时针和分针之间的时差.因此,该函数现在看起来像:

So, you need to find the difference between the hour and the minute hand. Thus the function now looks like:

def clockangles(hour, minute):
    return (hour * 30 + minute * 0.5) - (minute * 6)

现在,这是有效的,所以我们可以在这里停止.但是,我应该解释一下,这既可以给出大于180度的答案,也可以给出负角度的答案.如果您不想要这些东西(从您的评论看来,您不需要),请更正它们.

Now, this is valid, so we could stop here. However I should explain that this can give both answers larger than 180 degrees and negative angles. If you don't want those things (and from your comments it appears that you don't), correct for them.

def clockangles(hour, minute):
    return abs((hour * 30 + minute * 0.5) - (minute * 6))

现在,没有负角了.

def clockangles(hour, minute):
    ans = abs((hour * 30 + minute * 0.5) - (minute * 6))
    return min(360-ans,ans)

现在,顺时针和逆时针测量形成的两个角度中的较短者.

Now, the shorter of the two angles formed by measuring clockwise and counterclockwise.

这篇关于如何计算时针和分针之间的角度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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