counterclock

Richard Suchenwirth 2005-05-19 - Mathematicians are well aware of the importance of counterclockwise orientation. For the rest of us, who wonder how it looks like, here's a counterclock that goes the other way round, strongly based on a little A-D clock :) The direction is in the global variable sense - click on the window to reverse it.

WikiDbImage counterclock.gif

HJG The window-title (and taskbar-text) now put to use...

proc main {} {
    set ::sense -1
    pack [canvas .c -width 100 -height 100]
    for {set i 1} {$i<13} {incr i} {
        set a [expr {$i/6.*$::sense*acos(-1)}]
        set x [expr {50 + 43 * sin($a)}]
        set y [expr {50 - 43 * cos($a)}]
        .c create text $x $y -text $i -tag t
    }
    wm geom . 128x100
    # every 100 {drawhands .c 50 50}
    every 500 {set time [clock format [clock sec] -format %H:%M:%S]
               drawhands .c 50 50; wm title . $time }
 
    bind .c <1> {set sense [expr -$sense]; .c scale t 50 50 -1 1} 
}
proc drawhands {w xm ym} {
    $w delete hands
    set secSinceMidnight [expr {[clock seconds] - [clock scan 00:00:00]}]
    foreach divisor {30 1800 21600} length {40 35 30} width {1 2 3} {
        set angle [expr {$secSinceMidnight*$::sense*acos(-1) / $divisor}]
        set x [expr {$xm + $length * sin($angle)}]
        set y [expr {$ym - $length * cos($angle)}]
        $w create line $xm $ym $x $y -width $width -tags hands
    }
}
proc every {ms body} {eval $body; after $ms [namespace code [info level 0]]}

main

AM 2005-05-10: I could not resist commenting on the introductory remarks :)

Quite apart from clockwise and counterclockwise directions, there is also the matter of using the positive x-axis as the reference, instead of the positive y-axis. This is all about conventions, of course, but you would be surprised by the confusion they may cause - see Angles and directions for an earlier "lamentation" on the subject.

In short: a mathematician (and, by proxy, a physicist) would devise a clock running from 0 to 11, where the 0 mark is at the right and the hands move in a leftward direction - counterclockwise you might say, but if such a clock were standard, it would not be a counter direction ...

CLN: Ah, handism rears its ugly head again! Speaking as a lefty, I have to ask, Why is a right-handed coordiate system better than a left-handed one? ;-)

AM: (In a conspiratory voice, as a fellow-lefty) In a right-handed system you actually rotate things leftwise! There have been rumours that the universe is right-handed - but I take that to be a vile plot ...

Larry Smith: It's a neurological fact that each side of a human body is controlled by the opposite side of the brain. It therefore follows that only lefties are in their right minds... =)

RS: confesses that he was born left-handed but retaught - only with tools like hammers or badminton or table-tennis rackets, my left hand does better :)


AM: Whimsical design for a "true" mathematicians' clock:

  • The clock is divided into 17 sectors
  • The numbers start with zero and run up to 16
  • Zero is placed on the positive x-axis
  • The hands move in the counter-clockwise direction

An artistic touch could be to replace the numbers by the names of famous mathematicians, appearing in chronological order.

You may ask: why 17 sectors? And I answer: Gauss!

This giant among mathematicians was the first to show that a regular 17-gon can be constructed using classical rules ...

Lars H: In other words, we don't do it using 13 sectors, because there's no way to construct the regular 13-gon using only ruler and a pair of compasses. Mathematics has accumulated quite a lot of such very special solutions over the years, but books are not always keen on explaining just how special the solutions are. ;-)

AM: Alas, that is quite true! Mathworld [L1 ] has several pages on constructions with just a ruler and compasses or with variations on the classical rules. More detailed information on what constructions are possible is distributed over many many books - each containing just a few examples ...

I chose the 17-gon because it was a remarkable addition to Greek geometry! I have seen mention of the heptagon, nonagon and the 13-gon using a marked straightedge, IIRC, but that is all. To illustrate that it is not all that simple: it seems it took a guy called Hermes 10 years to find the construction of the 65537-gon (the possibility was predicted by Gauss). The irony is that with just a compass you get a very good approximation of that polygon ...

HJG: When drawn with alternating colors, the hours are much easier to read...


proc main {} {
    set ::sense -1
    set ::mode 24
    pack [canvas .c -width 100 -height 100]
    for {set i 1} {$i<=$::mode} {incr i} {
        set a [expr {2*$i/double(${::mode})*$::sense*acos(-1)}]
        set x [expr {50 + 43 * sin($a)}]
        set y [expr {50 - 43 * cos($a)}]
        set c [expr {$i%2 ? {white} : {black}}]       ;# alternate colors
        .c create text $x $y -text $i -tag t -fill $c
    }
    every 100 {drawhands .c 50 50}
    bind .c <1> {set sense [expr -$sense]; .c scale t 50 50 -1 1}
}
proc drawhands {w xm ym} {
    $w delete hands
    set secSinceMidnight [expr {[clock seconds] - [clock scan 00:00:00]}]
    foreach divisor [list 60 3600 [expr {86400*$::mode/24.0}]] length {40 35 30} width {1 2 3} {
        set angle [expr {$secSinceMidnight*$::sense*2*acos(-1) / $divisor}]
        set x [expr {$xm + $length * sin($angle)}]
        set y [expr {$ym - $length * cos($angle)}]
        $w create line $xm $ym $x $y -width $width -tags hands
    }
}
proc every {ms body} {eval $body; after $ms [info level 0]}

main

Almost the same code, with an extra parameter mode, giving the number of hours to display (24 hours here, as I've seen on some (marine?, italian?) wall clock). Setting mode to 12 give the standard 12 hours watch. You can of course set it to more exotic values, as 10 or 17 for instance. (PBO)


Same code again, but this version handles resizing of the main window:

proc main {} {
    set ::sense -1
    set ::mode 24
    set ::every_timer {}
    pack [canvas .c -width 100 -height 100] -fill both -expand yes
    bind .c <1> {set sense [expr -$sense]; .c scale t 50 50 -1 1}
    bind .c <Configure> [list redraw_digits %W %w %h]
}
proc drawhands {w xm ym} {
    $w delete hands
    set secSinceMidnight [expr {[clock seconds] - [clock scan 00:00:00]}]
    foreach divisor [list 60 3600 [expr {86400*$::mode/24.0}]] length {0.8 0.7 0.6} width {1 2 3} {
        set angle [expr {$secSinceMidnight*$::sense*2*acos(-1) / $divisor}]
        set x [expr {$xm + $length * $xm * sin($angle)}]
        set y [expr {$ym - $length * $ym * cos($angle)}]
        $w create line $xm $ym $x $y -width $width -tags hands
    }
}
proc every {ms body} {
    after cancel $::every_timer
    eval $body
    set ::every_timer [after $ms [namespace code [info level 0]]]
}
proc redraw_digits {w width height} {
    $w delete all
    set w2 [expr {$width/2.0}]
    set h2 [expr {$height/2.0}]
    set radius 0.86
    for {set i 1} {$i<=$::mode} {incr i} {
        set a [expr {2*$i/double(${::mode})*$::sense*acos(-1)}]
        set x [expr {$w2 * (1 + $radius*sin($a))}]
        set y [expr {$h2 * (1 - $radius*cos($a))}]
        set c [expr {$i%2 ? {white} : {black}}]       ;# alternate colors
        $w create text $x $y -text $i -tag t -fill $c
    }
    set cmd {set sense [expr -$sense];}
    append cmd [list $w scale t $w2 $h2 -1 1]
    bind $w <1> $cmd
    every 100 [list drawhands $w $w2 $h2]
}
main

Ralf Fassel