【问题标题】:To determine the time when the angle between the clock hands is known in analog clock in android在android中的模拟时钟中确定时钟指针之间的角度已知的时间
【发布时间】:2012-01-05 09:20:53
【问题描述】:

我想从 Android 应用程序中的模拟时钟设置时间。为此,我重写了 Analogclock.java 类并建立了 Ontouchevent 监听器。我按照 this methodthis formula 从获得的坐标计算时针和分针之间的角度。现在我可以将手移到一个新的位置。我还可以从中获取针之间的新角度。这是相同的代码:

   case MotionEvent.ACTION_MOVE: 
        x = (int)event.getX();
        y = (int)event.getY();
        double dx = x - minuteRect.centerX();    
        double dy = -(y - minuteRect.centerY()); 
        double inRads = Math.atan2(dy,dx);      

        if (inRads < 0) 
            inRads = Math.abs(inRads);
        else
            inRads = 2*Math.PI - inRads;      

        double newDegree =  Math.toDegrees(inRads); 
        if(isMove()){
            setAngle(newDegree);
            invalidate(); 
        } 

我现在想设置针移动的时间。 有什么方法可以从坐标或两个针之间的角度计算时间

【问题讨论】:

    标签: java android math clock


    【解决方案1】:

    我不知道代码,但数学并不难:

    将时针的角度除以 2PI,再乘以 12 并截断,就得到了小时数。 将分针的角度除以 2PI,再乘以 60 并截断,就得到了分针。

    示例:06:15:

    • 小时角比 PI 稍微大一点。 (PI / 2PI) * 12 = 6
    • 微小角度为 PI/2。 ((PI/2) / 2PI) * 60 = 15

    【讨论】:

    • 但是我只知道两根针之间的角度。为了得到小时的角度,我看到的公式是 - 1/2(60*Hr+Min)。但就我而言,我不会有更新的会议记录。我只有上面代码中的针和时钟坐标之间的角度 - (x,y)
    • 在您的情况下,您是如何判断 PI/2 是分钟角的?和 PI 作为小时角?
    • 如果以y轴正方向为参考(即12点),如果是6:15,则时针的角度为pi,分针的角度为PI/2.
    猜你喜欢
    • 2019-12-31
    • 1970-01-01
    • 2022-12-06
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多