[vtkusers] Re: vtkmath in tcl

Goodwin Lawlor goodwin.lawlor at ucd.ie
Fri Jul 22 12:14:18 EDT 2005


Hi Mark,

>     scan $a "%f %f %f" ax ay az
>     scan $b "%f %f %f" bx by bz
> 
> with
> 
>     foreach {ax ay az} $a {break}
>     foreach {bx by bz} $b {break}

That's a cool trick!

I changed myCrossProd a little to:

proc myCrossProd {a b} {

    if {[llength $a] < 3 || [llength $b] < 3} {
        return -code error "Vectors must have 3 components!"
    }

    foreach {ax ay az} $a {break}
    foreach {bx by bz} $b {break}

    return [list [expr {$ay*$bz - $az*$by}] [expr {$az*$bx - $ax*$bz}] 
[expr {$ax*$by - $ay*$bx}]]
}

and got times of 4 microseconds per iteration (~1 microsecond less than 
I get for your original- sometimes I get 4, somtimes I get 5)

Next time I'm building vtk I'll wrap the c++ methods and see what times 
I get... these pure tcl procs aren't bad though.

Goodwin




More information about the vtkusers mailing list