Results 1 to 29 of 29

Thread: Hands on a clockface (resolved)

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Hands on a clockface (resolved)

    How to you calculate the angle of the MinuteHand and the HourHand of a clock, when you are given the time as the number of seconds since midnight?

    Angles in radians would be fine.

    Thanks.

    EDIT: I don't want the angle between the hands, just the angle individually: say its 3:00am, the minute hand is at 0 radians (0 degrees) and the hour hand is at 1.570796 radians (90 degrees).
    Last edited by wossname; Sep 11th, 2004 at 01:06 PM.
    I don't live here any more.

  2. #2
    Lively Member Doddddy's Avatar
    Join Date
    Jul 2004
    Location
    Cluj-Napoca, Romania
    Posts
    109
    mhandAngle = (time MOD 60^2) * 2 * PI / 60^2
    hhandAngle = (time MOD 60^3) * 2 * PI / 60^3

    of course it could be completely wrong
    'nothin last forever even cold november rain

  3. #3
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    for hours: angle = 2 * pi * h / 12 = pi * h / 6
    for minute / seconds: angle = 2 * pi * h / 60 = pi * h / 30

    [edit]: this is my 911th post.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  4. #4
    Lively Member Doddddy's Avatar
    Join Date
    Jul 2004
    Location
    Cluj-Napoca, Romania
    Posts
    109
    i think he wanted the exact location of the hands
    'nothin last forever even cold november rain

  5. #5
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    Go ahead, put in 6:00, or 6:30. You will get pi for hours and 0 and pi (respectively) for the other.

    I don't see what you mean.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  6. #6

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Another way of asking the same question...

    How many radians does the hour hand travel through per second?
    How many radians does the minute hand travel through per second?



    My ropey maths tells me that the minute hand travels through 0.0000290882087 radians per second, and the hour hand 0.0000005076956996 radians per second. Is this right?

    Since a second hand does 6 degrees per sec, divide by 60 to get minute hand degrees per second and divide by 60 again to get hour hand, then convert each of those to radians.

    If I multiply these figures by the number of seconds since midnight I should be left with the correct angle for each hand. Does this seem logical?
    I don't live here any more.

  7. #7
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    I think in degrees, not radians but here's something I'll cook up on the go.
    rotate the hands clockwise where 0 degrees is striaght up.

    minangle = minutes*60
    hourangle = (hours*60)+minutes
    Have I helped you? Please Rate my posts.

  8. #8

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    I normally use degrees too but the framework math.sin() and math.cos() have to be supplied with radians in order to work.

  9. #9

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    w00t!

    Took 3 expressos to get this finished. I'll finish polishing my Clox0r class and post it up here when all the bugs have been eradicated.

    Meanwhile, here's a screenshot...



    Graphically, the hands of the clock are accurate to a 10,000,000th of a second. You can even get it to sweep smoothly around the clock (like on Back To The Future )!

    The constructor lets you specify the radius of the clockface, the x,y position of the centre of it and the graphics object you want to draw the clock on. (Just had it drawing onto a Button control ).
    Attached Images Attached Images  
    I don't live here any more.

  10. #10

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Mk2.



    Clox0r drawing itself onto a Button control's Graphics object via button_Paint(). Clicking the button pops up a message box, meanwhile the clock keeps ticking on the button!

    Attached Images Attached Images  
    I don't live here any more.

  11. #11
    Lively Member Doddddy's Avatar
    Join Date
    Jul 2004
    Location
    Cluj-Napoca, Romania
    Posts
    109
    omg. i simply must have it
    'nothin last forever even cold november rain

  12. #12

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    My finely honed superhero senses suggest that there may have been a soupçon of sarcasm in that last comment.

    I can take it. Mummy says I'm a grown up now.

    Eat shadows punk!...

    Attached Images Attached Images  
    I don't live here any more.

  13. #13
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    but can it run BACKWARDS???

  14. #14

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    You feed it Timespan Objects and it will go in whatever direction you want, feed it the right times and you can get the hour and minute hands to spin in opposite directions

    VB Code:
    1. dim cf as Clox0r = new Clox0r(...)
    2. ...
    3.  
    4. dim temp as Timespan = new Timespan(0)
    5.  
    6. for i as integer = 0 to 99999
    7. cf.Time = cf.Time.AddMinutes(59)
    8. cf.Draw
    9. Delay()
    10. next i
    Last edited by wossname; Sep 13th, 2004 at 03:26 AM.

  15. #15
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Does it tell the time?

  16. #16

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Originally posted by mendhak
    Does it tell the time?
    Does it tell the what now? Stop trying to complicate matters reptile.
    I don't live here any more.

  17. #17
    Lively Member Doddddy's Avatar
    Join Date
    Jul 2004
    Location
    Cluj-Napoca, Romania
    Posts
    109
    Originally posted by wossname
    My finely honed superhero senses suggest that there may have been a soupçon of sarcasm in that last comment.

    I can take it. Mummy says I'm a grown up now.

    Eat shadows punk!...

    Kool off kitty...
    I meant no harm, just like to joke sometimes. its a nice control
    'nothin last forever even cold november rain

  18. #18
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    Too cool. A lawyer/friend of mine has a timepiece that runs backwards, and I'd love to give him this for his computer, as a joke!

  19. #19

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    I'm just writing the documentation now. Should be able to post it tonight.
    I don't live here any more.

  20. #20
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    What algorithm did you use to find the position of the hands?
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  21. #21
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    can I have it? let me know. i need it to run backwards, though.

  22. #22

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Originally posted by Darkwraith
    What algorithm did you use to find the position of the hands?
    I wrote a Hand class and as a Constructor argument I pass in the speed of the particular hand in question. Then the class multiplies this value by the ticks property of the time. The speed is expressed as the number of radians that the hand passes through per tick (Pretty microscopic number!). And so this multiplication gives the angle that the hand shoulld be shown at. This is typically several million radians.

    The Clox0r class (the whole thing) will be released as part of the Sandpaper library (see the Project Communication forum here)

    Source will not be available I'm afraid. And yes, it will be able to run backwards Stay tuned.

  23. #23
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    ok... I see now. Thanks.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  24. #24
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    10-4. he'll have to wait.

  25. #25
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    I mean that I know how he did it from his pseudocode and why he did it as such.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  26. #26

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    If you are interested, the shape of the hands was defined as an array of PointF objects. the .X property of which represented the Angle of the point in radians, and the .Y property was the distance away from the origin. Polar Coordinates in other words.

    Then its just a simple job of adding the each .X to the angle of the hand and drawing the resulting polygon. Simple and precise.
    I don't live here any more.

  27. #27

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    I don't live here any more.

  28. #28
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    .Net only, also!

  29. #29
    Banned WonkoTheSane's Avatar
    Join Date
    Nov 2004
    Location
    Jersey, nr France
    Posts
    8
    Originally posted by dglienna
    .Net only, also!
    In order to elaborate.

    This clock class is only available in .net format. This is because VB6 is a bit naff.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width