模拟时钟算法? [英] Analog Clock algorithm?

查看:139
本文介绍了模拟时钟算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我有很多关于如何创建模拟时钟的源代码,但是我无法理解算法,尤其是使用"sin"和"cos",因此请任何人都可以帮助我提供有关理解的教程.算法

I have a lot of source code for how to create an anlog clock but i cant understand the algorithm, esp use of 'sin' and 'cos', so please any one can help me with a tutorial for the understanding of the algorithm,

感谢和问候

推荐答案

我将接受这一挑战...

I'll take this chanllenge...

所有这些算法都从长度/宽度/颜色(时针,分针,秒针)不同的点(时钟中心)到不同角度(不同时间)画线.

All these kind of algorithms draw lines from a point (center of your clock) with different length/width/color (hour arm, minute arm, second arm), towards different angle (different time).

假设您的时钟中心在(x,y),臂的长度为r,角度为a,那么您需要计算第二个点(x1,y1),以便可以在( x,y)和(x1,y1)来绘制时钟臂.

Assume your clock center is at (x,y), the length of the arm is r, and the angle is a, then you need to calculate a second point (x1, y1) so you can draw a line between (x,y) and (x1, y1) to paint a clock arm.

如果您对'sin'和'cos'遇到困难,则可以将以下方程式用作公式

If you have difficulties with 'sin' and 'cos', you can just use the following equations as formulas

x1 = x + r * sin(a);

x1 = x + r*sin(a);

y1 = y-r * cos(a);

y1 = y - r*cos(a);

注意关于角度"a".在上述公式中,如果手臂点向上拉紧(在12个时钟点),则a = 0

NOTE about angle "a". In above formula angle a = 0 if the arm point straing up (at 12 clock)

现在如何获得不同手臂的这些角度

Now how to get these angles for different arms

对于第二条手臂,只需将0-60映射到0-360就可以了.这很容易,只需将第二个值乘以6.(每秒钟手臂将旋转6度,您将获得15秒= 90度, 30秒= 180度,等等.

for second arm, it's a matter of mapping 0-60 to 0 - 360. This is easy, just multiple the second value by 6. (Each second the arm will rotate 6 degree, you get 15 second = 90 degree, 30 second = 180 degree, etc.)

分钟臂与第二臂相同,因为它也在0-60到0-360之间映射

Minute arm is the same as second arm, as it's also mapping 0-60 to 0-360

时针并不是那么简单,因为模拟时钟程序通常不会将0-12映射到0-360-很多时候您会注意到时针指向两个读数的中间,指示时间介于两个读数之间小时.在这种情况下,映射是0-720(分钟)到0-360.映射很容易(除以2).这意味着,每经过一分钟,时针就会旋转一半度.在12个小时(720分钟)之后,以这种速度,时针将完成一个圈.

for hour arm is less straightforward, as analog clock programs usually don't map 0-12 to 0-360 - very often you notice the hour arm is pointing in the middle of two readings, incidating the time is between the two hours. In this case the mapping is 0-720 (minutes) to 0-360. The mapping is easy (divide by 2). This means for each minute passes, the hour arm rotates half degree. At this speed after 12 hours (720 minutes) the hour arm will complete a circle.

最后,您需要将度数转换为radain,这是C#要求的.要将角度a转换为弧度,可以使用公式

At last, you'll need to convert degree to radain as it's what requested by C#. To convert angle a to radian, you can use formula

a = a *数学PI/180

a = a * Math.PI / 180

然后将a插入公式以计算(x1,y1)

then plug a to the formula to calculate (x1, y1)


这篇关于模拟时钟算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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