something seem to be wrong with 11 O'clock
Main Topics
Browse All TopicsI'm working on a software program with a clock control. I have the angle calculated where 1-30 degrees is 2 o clock, 31-60 degrees is 1 and so on in counter clockwise direction. So to list them all
Time/Degrees
12/ 61-90
1/31-60
2/1-30
3/331-360
4/301-330
5/271-300
6/241-270
7/211-240
8/181-210
9/151-180
10/121-150
11/61-90
What would be a formula if given the angle you could find the hour?
What would be the formula to find out which minute the minute hand is pointing to if given the angle of it?
And if possible, how would you find the correct angle of the minute hand if given the angle of the hour hand on this degree setup?
Thanks a ton to any math whizzes, this is not homework I promise. Its a real issue I'm dealing with on a .NET control.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
"What would be the formula to find out which minute the minute hand is pointing to if given the angle of it?"
What does the minute hand make an angle with?
do you start with the angle that the minute hand makes with the vertical? or with the direction from center to 2? Or the angle it makes with the hour hand?
The hour code worked great. The minute code gave weird results but like you said the zero degrees starting at 2 is odd and makes this more difficult. It comes from the method below. Do you see any way to fix it where 12 would be 0 degrees and then it would continue clockwise to 360?
To clarify on my last question. If a user were to drag the hour hand halfway between the 2 and 3, using angle-to- hour formula we know they want the hour to be 2'Oclock but at that degree (assuming the method below were working correctly and 12'oclock was 0 degrees and moved onward clockwise, say they clicked on 76 degrees when they clicked halfway between 2-3) what degree should the minute hand be set out to properly reflect the time when the hour hand is at that degree. (halfway between 2 and 3)
Thank you very much for your time and replies.
Well, if billprew's formula
i=truncate(angle/30)
if i>1 then h=14-i else h=2-i
worked for h, then it can be slghtly rewritten as follows:
t = 2.0 - angle/30.0
if t < 1.0 then t = t + 12.0
h = truncate(t)
This should still give the same hour, but we can add a line to calculate the minutes from the rest:
m = truncate(60*(t-h))
Using a modified version of your procedure shown below, this should return the angle of the mouse position relative to the origin, with 0 degrees at the top (12:00), and 180 degrees at the bottom (6:00). This makes the calculation of the hours or minutes from degrees simpler as:
h=truncate(angle/30)
if h<1 then h=h+12
m=truncate(angle/6)
I think you also need to add code to you routine to handle the case where X and/or Y equal the origin X or origin Y, since those are special cases and some can cause division by zero.
~bp
I assumed you mean't to change the last line on angle =. Did so and got 0 degrees at 6'oclock, and incrementation to 360 counterclockwise. If some kind of mirror effect could be applied it would be working correctly I think?
Any idea what the problem could be?
Thanks so much for your continued assistance.
Well, not sure what is going on here, unless what I'm thinking of on paper isn't matching the coordinates you are using. I'm attaching an Excel sheet with a number of test cases, and the calculations that should be occurring in your routine now. The Excel sheet seems to give the results I am expecting.
The first four columns should make sense, they are just the origin X and Y, and the data point X and Y. Then I calculated the "based" value as you should be. Then I calculated the angle in radians for these points. Next I convert to degrees (angle*180/PI). Lastly I add to the "biased" value. I am seeing values as I would have expected in the sheet.
~bp
Could it be something to do with the fact that as I go from left to right on my clock face the mouse position returned on the X axis increases (as expected) but when I go up on the Y axis, the Y cordinate decreases. When I go down, the Y Cordinate increases. Shouldn't the Y axis go up and my mouse goes up and vice versa? I'm just using the point returned from my mouse click event..
From Cordinate system being utilized, here are the values of X/Y at various points on the clock. (approx)
Clock Angle:
X: 69 Y: 23 Angle 180 12'oclock
X: 112 Y: 66 Angle 93.9 3'oclock
X: 91 Y: 105 Angle 31.4 5'oclock
X: 47 Y: 106 Angle 329.2 7 o clock
X: 27 Y 66 Angle 265 9 'oclock
X: 48 Y: 32 Angle 209 11'oclock
Perhaps that is the discrepancy? Never does the coordinate system used in the control go into the negative.
Brilliant! Works great!! Was beginning to think I was seeing numbers backwards or something =)
Thanks a ton! Here is a follow-up question I just posted:
http://www.experts-exchang
Business Accounts
Answer for Membership
by: billprewPosted on 2009-09-12 at 18:24:37ID: 25318596
Something like this will get the hour (h) based on the angle samples you gave:
i=truncate(angle/30)
if i>1 then h=14-i else h=2-i
For the minute hand I'd want to see some sample data like you gave for the hour, but it could be similar to the hour and look like:
i=truncate(angle/6)
if i>1 then h=70-i else h=10-i
I don't understand the third part of your question.
Why did you set zero degrees at 2:00 rather that 12:00, seems odd.
~bp