So I'm trying to code this program but the code I keep trying is wrong or just doesn't give me the right answers. I need to code a program that will compute the angles of clock hands in military time. The angles that I need are:
Angle between Second and Minute hands
Angle between Minute and Hour hands
Personally I think my equation is wrong but I'm having trouble fixing it. Can someone tell me what is wrong with my code and give me some advice on how to fix it? Thank you in advance for any help!!
Switching the equations does work, but it works for most generic angles. If I enter a complicated angle however, I don't get decimals in my angles. It just rounds to whole numbers which doesn't really make sense. I'm not sure why it is doing that.
When we look at seconds we divide the clock in 360 degrees. making 45 seconds at 270 degrees.
But for your wanted calculation to work the seconds need to be seen as the distance between 1 min and the next one min.
so place hour hand at 1 oclock and place the next hand 10.5 degrees lower and you have a hand that is 1min45 sec lower. but if you enter time 1h6min45 sec you get a different output. because when you place a hand 45 sec lower it is 3/4th of a min in distance but you told the program that 45 sec is not 3/4th of a min but infact 3/4th of the entire clock....
but i dont know how to solve that either, will keep thinking about it...
is your clock "smooth"? (does the minute hand "tick" between minutes or sweep?)
at half past the hour, do you expect the hour hand to be halfway between the hours?
at half past the minute, do you expect the minute hand to be halfway between the minutes?
maybe you need to add something not just hour, sec, min, but a new unit like a realminute. where the realminute is capable of using seconds without looking at the actual secondshand
first convert sec to percentage_of_minute
then the real_minute = minute + percentage_minute
while the hand of the seconds is at 45 sec/270 degrees, the hand of the actual time can only be at either 6 or 7 but the hand of the real_min can be between 6 and 7.
at 45 sec, the second hand would be at 270%, but it would also be represented between 6 and 7. 45 sec is 75% of min
real minute would be 0.75 min
the min hand at 6, but the real_min hand can be at 6,75. the reason why you would keep the min hand in addition to the real min hand would be to calculate the real_min hand in the first place...
I dont know how to do that in code, its my second day learning about C++, and it is probably not the prettiest way to code it.
then tackle the problem from the bottom up, by that i mean seconds influece minutes influence hours so calculate them in that order.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// the easy bit
double sec_angle = sec * degPerSec;
// calculate the partial minute that seconds equates to.
double partialMin = sec / secsPerMin;
// then take it into account when calculating the minute angle.
double min_angle = (min+partialMin) * degPerMin;
// calculate the partial hour that all minutes equate to.
double partialHour = (min+partialMin) / minsPerHour;
// then take it into account when calculating the hour angle.
double hour_angle = (hour+partialHour) * degPerHour;
If you are done with the complete code Spaceman Zeta would you be so kind to post it here or pm it? I wont use it for anything ofcourse but I really really really want to learn from this example.
@Cortega
The only learning that needs to be done is how to approach a problem.
1. always use const, it removes "magic numbers" from your code and stops you thinking at the micro level.
2. break it down.
3. find the dependencies and take the bottom first so you can build on it
when you read my code it's easy, because it follows common sense, you dont have to concentrate on the syntax of the language as the code is more or less "human readable" by that i mean you could read it out loud and it would make sense to a listener.
GL/HF
NB: You aleady identified the key points in your post, all i can add to that is dont mix it up, adding percentages to the mix added complexity.