Version 0 of Sine wave roundings illustrated with BWise

Updated 2006-02-09 18:28:36

started by Theo Verelst

When dealing with the solution of (2d order) differential equations, electrical circuits, drawing circles, making musical waves or fourier analysis, sine waves or sine values as function of lets say x are essential.

Lets first draw a sine wave with a reasonable graphical accuracy, make sure you have a (preferably scrollable) Tk canvas to work on, and that the tcl variable mc contains the path to that canvas.

This routine, called with the number of x-steps draws 2 periods of a sine wave, with 1:1 x:y scale ratio, and rouding of y coordinates by truncation:

 proc drawsine { {n 256} } {
   global mc
   set pi 3.1415926535
   $mc del gr
   for {set i 1} {$i < 2*$n} {incr i} {
      $mc create line [expr 100+$i-1] \
         [expr 100+$n-$n*sin(2*$pi*($i-1)/$n)] \
         [expr 100+$i] \
         [expr 100+$n-$n*sin(2*$pi*($i)/$n)] \
            -tag gr
   }
 }

 drawsine 256

http://82.170.247.158/Wiki/sine1m.jpg