Tcl wrapper for C interpolation procedures (v0.14)

::tclinterp::approximationTop, Main, Index

CommandsTop, Main, Index

bezier [::tclinterp::approximation]Top, Main, Index

Finds values of Bezier function at x points.

bezier -n value -a value -b value -x list -y list
Parameters
-aStart of the interval.
-bEnd of interval.
-nOrder of Bezier function, must be zero or more.
-xList of x values.
-yList of y control points values of size n+1.
Return value

yi values of Bezier function at x points

proc ::tclinterp::approximation::bezier {args} {

    # Finds values of Bezier function at x points.
    #  -n - order of Bezier function, must be zero or more
    #  -a - start of the interval
    #  -b - end of interval
    #  -x - list of x values
    #  -y - list of y control points values of size n+1
    # Returns: yi values of Bezier function at x points
    # Synopsis: -n value -a value -b value -x list -y list
    argparse {
        {-n= -required}
        {-a= -required}
        {-b= -required}
        {-x= -required}
        {-y= -required}
    }
    if {[string is integer -strict $n]==0} {
        return -code error "Order of Bezier curve -n '$n' must be of integer type"
    } elseif {$n<0} {
        return -code error "Order of Bezier curve -n '$n' must be more than or equal to zero"
    } elseif {$a==$b} {
        return -code error "Start -a '$a' and end -b '$b' values of interval must not be equal"
    }
    set xLen [llength $x]
    set yLen [llength $y]
    if {$yLen!=[= {$n+1}]} {
        return -code error "Length of -y '$yLen' must be equal to n+1=[= {$n+1}]"
    } elseif {$xLen==0} {
        return -code error "Length of points list -x must be more than zero"
    }
    ::tclinterp::lists2arrays [list yArray] [list $y]
    for {set i 0} {$i<$xLen} {incr i} {
        lappend yiList [::tclinterp::bez_val $n [@ $x $i] $a $b $yArray]
    }
    ::tclinterp::deleteArrays $yArray
    return $yiList
}

cubicBetaSpline1d [::tclinterp::approximation]Top, Main, Index

Evaluates a cubic beta spline approximant.

cubicBetaSpline1d -beta1 value -beta2 value -t|x list -y list -ti|xi list
Parameters
-beta1The skew or bias parameter, beta1 = 1 for no skew or bias.
-beta2The tension parameter, beta2 = 0 for no tension.
-tList of independent variable (t) values, -x is an alias.
-tiList of independent variable interpolation (ti) values, -xi is an alias.
-yList of dependent variable (y) values.
Return value

list of approximation values yi at ti points.

proc ::tclinterp::approximation::cubicBetaSpline1d {args} {

    # Evaluates a cubic beta spline approximant.
    #  -beta1 - the skew or bias parameter, beta1 = 1 for no skew or bias
    #  -beta2 - the tension parameter, beta2 = 0 for no tension
    #  -t - list of independent variable (t) values, -x is an alias
    #  -y - list of dependent variable (y) values
    #  -ti - list of independent variable interpolation (ti) values, -xi is an alias
    # Returns: list of approximation values yi at ti points.
    # Synopsis: -beta1 value -beta2 value -t|x list -y list -ti|xi list
    argparse {
        {-beta1= -required}
        {-beta2= -required}
        {-t= -required -alias x}
        {-y= -required}
        {-ti= -required -alias xi}
    }
    set tLen [llength $t]
    set yLen [llength $y]
    set tiLen [llength $ti]
    if {$tLen!=$yLen} {
        return -code error "Length of -y '$yLen' must be equal to length of -t '$tLen'"
    } elseif {$tiLen==0} {
        return -code error "Length of interpolation points list -ti must be more than zero"
    } elseif {[string is double -strict $beta1]==0} {
        return -code error "-beta1 '$beta1' must be of double type"
    } elseif {[string is double -strict $beta2]==0} {
        return -code error "-beta1 '$beta2' must be of double type"
    }
    ::tclinterp::lists2arrays [list tArray yArray] [list $t $y]
    for {set i 0} {$i<$tiLen} {incr i} {
        set iElem [::tclinterp::spline_beta_val $beta1 $beta2 $tLen $tArray $yArray [@ $ti $i]]
        lappend yiList $iElem
    }
    ::tclinterp::deleteArrays $tArray $yArray
    return $yiList
}

cubicBSpline1d [::tclinterp::approximation]Top, Main, Index

Evaluates a cubic B spline approximant.

cubicBSpline1d -t|x list -y list -ti|xi list
Parameters
-tList of independent variable (t) values, -x is an alias.
-tiList of independent variable interpolation (ti) values, -xi is an alias.
-yList of dependent variable (y) values.
Return value

list of approximation values yi at ti points.

proc ::tclinterp::approximation::cubicBSpline1d {args} {

    # Evaluates a cubic B spline approximant.
    #  -t - list of independent variable (t) values, -x is an alias
    #  -y - list of dependent variable (y) values
    #  -ti - list of independent variable interpolation (ti) values, -xi is an alias
    # Returns: list of approximation values yi at ti points.
    # Synopsis: -t|x list -y list -ti|xi list
    argparse {
        {-t= -required -alias x}
        {-y= -required}
        {-ti= -required -alias xi}
    }
    set tLen [llength $t]
    set yLen [llength $y]
    set tiLen [llength $ti]
    if {$tLen!=$yLen} {
        return -code error "Length of -y '$yLen' must be equal to length of -t '$tLen'"
    } elseif {$tiLen==0} {
        return -code error "Length of interpolation points list -ti must be more than zero"
    }
    ::tclinterp::lists2arrays [list tArray yArray] [list $t $y]
    for {set i 0} {$i<$tiLen} {incr i} {
        set iElem [::tclinterp::spline_b_val $tLen $tArray $yArray [@ $ti $i]]
        lappend yiList $iElem
    }
    ::tclinterp::deleteArrays $tArray $yArray
    return $yiList
}

genBezier [::tclinterp::approximation]Top, Main, Index

Finds values of general Bezier function at specified t points.

genBezier -n value -x list -y list -t list
Parameters
-nOrder of Bezier function, must be zero or more.
-tList of t points at which we want to evaluate Bezier function, best results are obtained within the interval [0,1]
-xList of x control points values of size n+1.
-yList of y control points values of size n+1.
Return value

dict with lists of xi and yi points at specified t points

proc ::tclinterp::approximation::genBezier {args} {

    # Finds values of general Bezier function at specified t points.
    #  -n - order of Bezier function, must be zero or more
    #  -x - list of x control points values of size n+1
    #  -y - list of y control points values of size n+1
    #  -t - list of t points at which we want to evaluate Bezier function, best results are obtained within the interval
    #   [0,1]
    # Returns: dict with lists of xi and yi points at specified t points
    # Synopsis: -n value -x list -y list -t list
    argparse {
        {-n= -required}
        {-x= -required}
        {-y= -required}
        {-t= -required}
    }
    if {[string is integer -strict $n]==0} {
        return -code error "Order of Bezier curve -n '$n' must be of integer type"
    } elseif {$n<0} {
        return -code error "Order of Bezier curve -n '$n' must be more than or equal to zero"
    }
    set xLen [llength $x]
    set yLen [llength $y]
    set tLen [llength $t]
    if {$xLen!=[= {$n+1}]} {
        return -code error "Length of -x '$xLen' must be equal to n+1=[= {$n+1}]"
    } elseif {$yLen!=[= {$n+1}]} {
        return -code error "Length of -y '$yLen' must be equal to n+1=[= {$n+1}]"
    } elseif {$tLen==0} {
        return -code error "Length of points list -t must be more than zero"
    }
    ::tclinterp::lists2arrays [list xArray yArray] [list $x $y]
    ::tclinterp::newDoubleps [list xiPnt yiPnt]
    for {set i 0} {$i<$tLen} {incr i} {
        ::tclinterp::bc_val $n [@ $t $i] $xArray $yArray $xiPnt $yiPnt
        lappend xiList [::tclinterp::doublep_value $xiPnt]
        lappend yiList [::tclinterp::doublep_value $yiPnt]
    }
    ::tclinterp::deleteArrays $xArray $yArray
    ::tclinterp::deleteDoubleps $xiPnt $yiPnt
    return [dcreate xi $xiList yi $yiList]
}