确定Android模拟时钟中时钟指针之间的角度已知的时间
我想在 Android 应用程序中通过模拟时钟设置时间。为此,我重写了 Analogclock.java 类并建立了 Ontouchevent 监听器。我遵循这个方法< /strong> 和 此公式 计算小时之间的角度和分针从获得的坐标。现在我可以将手移动到新位置。我还可以从中获取针之间的新角度。这是相同的代码:
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();
}
我现在想要设置针移动的时间。 有什么方法可以从坐标或两针之间的角度计算时间?
I want to set time from the analog clock in an Android Application. For this I have overridden the Analogclock.java class and have established the Ontouchevent listener. I followed this method and this formula to calculate the angle between the hour and the minute hand from the obtained Coordinates. Now I'm able to move the hand to a new position. And I can also fetch the new angle between the needles from this. This is the code for the same :
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();
}
I now want to set the time where the needle is being moved.
Is there any way I can calculate the time from the Coordinates or from the angle between the two needles?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道代码,但数学并不难:
将时针的角度除以 2PI,乘以 12 并截断,就得到了小时。
将分针的角度除以 2PI,再乘以 60 并截断,就得到了分钟。
示例: 06:15:
(PI / 2PI) * 12 = 6
((PI/2) / 2PI) * 60 = 15
I don't know the code, but the math is not hard:
Divide the angle of the hour hand by 2PI, multiply by 12 and truncate, and you have the hours.
Divide the angle of the minute hand by 2PI, multiply by 60 and truncate, and you have the minutes.
Example : 06:15:
(PI / 2PI) * 12 = 6
((PI/2) / 2PI) * 60 = 15