Greeting.
So far this forum has been very helpful so let me press my luck.
I have several instances of a sub-routine library for various analytical purposes. So, for instance, I have a "vector operator" library with things like cross-product, dot-product, magnitude, etc. I have never been quite sure the best way to implement them so that they are truly general purpose. The way I decided on is as in the following (cross product) example:
#returns a list (a la "array get" of alternating index/value for the crossproduct array
# to use: (eg) set alist [crossP vect1 vect2]. Note: use the vector names (no $)
# then, "array set {array name} $alist"
proc crossP {a b} {
upvar $a x
upvar $b y
set z(1) [expr $x(2)*$y(3) - $x(3)*$y(2)]
set z(2) [expr $x(3)*$y(1) - $x(1)*$y(3)]
set z(3) [expr $x(1)*$y(2) - $x(2)*$y(1)]
return [array get z]
}
My question is: is there a more efficient way to do this? Bob Rashkin
rrashkin@csc.com
So far this forum has been very helpful so let me press my luck.
I have several instances of a sub-routine library for various analytical purposes. So, for instance, I have a "vector operator" library with things like cross-product, dot-product, magnitude, etc. I have never been quite sure the best way to implement them so that they are truly general purpose. The way I decided on is as in the following (cross product) example:
#returns a list (a la "array get" of alternating index/value for the crossproduct array
# to use: (eg) set alist [crossP vect1 vect2]. Note: use the vector names (no $)
# then, "array set {array name} $alist"
proc crossP {a b} {
upvar $a x
upvar $b y
set z(1) [expr $x(2)*$y(3) - $x(3)*$y(2)]
set z(2) [expr $x(3)*$y(1) - $x(1)*$y(3)]
set z(3) [expr $x(1)*$y(2) - $x(2)*$y(1)]
return [array get z]
}
My question is: is there a more efficient way to do this? Bob Rashkin
rrashkin@csc.com