#!/usr/local/bin/wish proc xydist {x1 y1 x2 y2} { return [expr {hypot(($x1 - $x2),($y1 - $y2))}] } proc line2spline {points} { lappend results [lindex $points 0] [lindex $points 1] for {set i 2} {$i < [expr [llength $points] - 2]} {incr i 2} { set h [expr $i - 1] set j [expr $i + 1] set x1 [lindex $points [expr $i - 2]] set y1 [lindex $points [expr $i - 1]] set x2 [lindex $points [expr $i + 0]] set y2 [lindex $points [expr $i + 1]] set x3 [lindex $points [expr $i + 2]] set y3 [lindex $points [expr $i + 3]] set xm1 [expr ($x1 + $x2)*0.5] set ym1 [expr ($y1 + $y2)*0.5] set xm2 [expr ($x3 + $x2)*0.5] set ym2 [expr ($y3 + $y2)*0.5] set dx [expr $x3 - $x1] set dy [expr $y3 - $y1] set dist1 [xydist $xm1 $ym1 $x2 $y2] set dist2 [xydist $xm2 $ym2 $x2 $y2] if {$dist1 < $dist2} { set dist [expr $dist1 * 0.5] } else { set dist [expr $dist2 * 0.5] } set angle atan2($dy,$dx) set deltax [expr $dist * cos($angle)] set deltay [expr $dist * sin($angle)] lappend results [expr $x2 - $deltax] [expr $y2 - $deltay] [expr $x2 + $deltax] [expr $y2 + $deltay] } lappend results [lindex $points end-1] [lindex $points end] return $results } proc poly2spoly points { lappend points [lindex $points 0] [lindex $points 1] [lindex $points 2] [lindex $points 3] for {set i 2} {$i < [expr [llength $points] - 2]} {incr i 2} { set h [expr $i - 1] set j [expr $i + 1] set x1 [lindex $points [expr $i - 2]] set y1 [lindex $points [expr $i - 1]] set x2 [lindex $points [expr $i + 0]] set y2 [lindex $points [expr $i + 1]] set x3 [lindex $points [expr $i + 2]] set y3 [lindex $points [expr $i + 3]] set xm1 [expr ($x1 + $x2)*0.5] set ym1 [expr ($y1 + $y2)*0.5] set xm2 [expr ($x3 + $x2)*0.5] set ym2 [expr ($y3 + $y2)*0.5] set dx [expr $x3 - $x1] set dy [expr $y3 - $y1] set dist1 [xydist $xm1 $ym1 $x2 $y2] set dist2 [xydist $xm2 $ym2 $x2 $y2] if {$dist1 < $dist2} { set dist [expr $dist1 * 0.5] } else { set dist [expr $dist2 * 0.5] } set angle atan2($dy,$dx) set deltax [expr $dist * cos($angle)] set deltay [expr $dist * sin($angle)] lappend results [expr $x2 - $deltax] [expr $y2 - $deltay] [expr $x2 + $deltax] [expr $y2 + $deltay] } return $results }