[img_rotate_ellipse1] ====== # EllipseRotate.tcl # Author: Gerard Sookahet # Date: 09 Marche 2019 # Version: 0.1 # Description: Simple graphical example of parametric equation of rotated ellipse # # xo,yo : centre of the ellipse # angle : rotation angle from 0 to 7 with the scalebar # a : major radius # b : minor radius # t : parameter package require tk bind all {exit} proc EllipseRotate {xo yo a b angle t} { set cosa [expr {cos($angle)}] set sina [expr {sin($angle)}] set cost [expr {cos($t)}] set sint [expr {sin($t)}] set x [expr {$xo + $a*$cosa*$cost - $b*$sina*$sint}] set y [expr {$yo + $a*$sina*$cost + $b*$cosa*$sint}] return [list $x $y] } proc EllipsePlot {w xo yo a b pi angle} { $w delete all lassign [EllipseRotate $xo $yo $a $b $angle 0] x2 y2 for {set p 0} {$p <= 720} {incr p} { set t [expr {$pi*$p/360}] lassign [EllipseRotate $xo $yo $a $b $angle $t] x1 y1 .c create line $x1 $y1 $x2 $y2 -fill blue -width 3 set x2 $x1 set y2 $y1 } } set width 600 set height 400 set pi 3.1415926 set xo [expr {$width/2}] set yo [expr {$height/2}] set a 200 set b 100 set angle [expr {$pi/6}] pack [canvas .c -width $width -height $height -background black] pack [scale .sc -from 0 -to 7 -length 240 -resolution .1 \ -orient horiz -bd 1 -showvalue true -variable angle \ -command {EllipsePlot .c $::xo $::yo $::a $::b $::pi}] ======