My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
tclspline  
spline - Generate a set of quadratic splines based on an input list
Updated Jun 11, 2009 by karllehe...@gmail.com

Synopsis

spline nSteps pointList

spline_raw nSteps pointList

Moved

Moved to github tclspline project

Description

Input is an integer number of steps, nSteps, and a list containing three or more pairs of x and y coordinates. spline reads that list and generates a new list of x and y coordinate pairs representing a curve based on the passed points, rendered as a set of quadratic splines: one spline is drawn for the first and second line segments, one for the second and third, and so on.

Straight-line segments can be generated within a curve by duplicating the end-points of the desired line segment.

spline_raw indicates that the list should also be returned as a curve, but the list of coordinates is such that the first coordinate pair (and every third coordinate pair thereafter) is a knot point on a cubic Bezier curve, and the other coordinates are control points on the cubic Bezier curve.

Straight line segments can be generated within a curve by making control points equal to their neighboring knot points. If the last point is a control point and not a knot point, the point is repeated (one or two times) so that it also becomes a knot point.

nSteps specifies the degree of smoothness desired for curves: eachspline will be approximated with nSteps line segments.

Comment by r_haer...@gmx.de, Feb 28, 2009

Example Usage

package require tclspline

set c [canvas .c]
pack $c -expand 1 -fill both 

proc linecoords { y {amplitude 50}} {

    for {set i 0} {$i < 600} {incr i 55} {
       set sign 1.0
       if { $i % 2 } {
	  set sign -1.0
       }
       lappend coords $i [expr {$sign * $amplitude + $y} ]
    }
    return $coords
}

set y 50
$c create line [linecoords $y]

foreach {steps color} {2 skyblue1 5 skyblue2 10 skyblue3 50 orange2 100 orange3} {

    incr y 10
    set coords [linecoords $y]
    set cmd [list set splinecoords [spline $steps $coords]]

    set duration [time $cmd]
    set t [format "% 14s for %4d steps" $duration $steps]
    puts $t
    set id [$c create line $splinecoords -fill $color]
    $c create text 20 [expr {$y * 1.5 + 80}] -text $t -fill $color -anchor w
}
Comment by project member karllehe...@gmail.com, Feb 28, 2009

Nice.. Thanks!


Sign in to add a comment
Powered by Google Project Hosting