开发者

Angle that a point clicked makes with vertical

开发者 https://www.devze.com 2023-03-02 13:53 出处:网络
I need to create analog clock in which hours is displayed at centre and minutes on circumference of circle.I need to calcula开发者_如何学Gote angle that the point on circumference where user clicks, m

I need to create analog clock in which hours is displayed at centre and minutes on circumference of circle.I need to calcula开发者_如何学Gote angle that the point on circumference where user clicks, makes with vertical to calculate minutes.Any help would be useful..


The formula would be

angle/totalDegrees * 60

Depending on how you've got your angle defined ofcourse, but lets default to 'normal' degrees: you've got 60 minutes and 360 degrees.

straight down, aka 180 degrees, would be 30 minutes. STraight up would be 0 minutes and 0 degrees, etc.

That would make your calculation

angle/360 * 60

You would have the mapping

180 -> 30
  0 ->  0
 90 -> 15


This gives the standard angle, positive x-as has angle of zero:

angle = Math.atan2(clicky-clockCenterY,clickx-clockCenterX)

To make 12 o'clock (angle of pi/2) the zero angle, just subtract pi/2:

angle = Math.atan2(clicky-clockCenterY,clickx-clockCenterX) - Math.Pi/2.0;

Javadoc for Math.atan2

The given angle is in radians (2pi for a full circle), to convert this to minutes (60 for a full circle):

minuteAngle = 60.0*(angle / (2.0*Math.Pi))

This might give a value of -15minutes, what should be 45 minutes so:

if (minuteAngle < 0.0)
  minuteAngle += 60.0;
0

精彩评论

暂无评论...
验证码 换一张
取 消