TUvecMath TCL UTILITIES USER MANUAL TUvecMath
SYNOPSIS
A set of mathematical operations applicalble to vector data.
PACKAGE
TCLUTILS
NAME
TUvecMath
USAGE
set rV  [TUvecMath  A Op B C {oA} {oB} {oC} {nA} {nB}
INPUT DEFINITIONS
A - Input vector A
Op - Operation
CROSS - Cross product of vectors A and B returned in vector C. Only valid for vectors of length 3.
DOT - Dot product of vectors A and B with value returned through routine.
MAG - Magnitude of vector A with value returned through routine.
UNIT - Unit vector of vector A returned in vector C.
TENSOR - Creates a tensor for vectors A and B by binomially multiplying them together. Tensor is returned in C.
OP - Produce the operation A OP B and return the result in C. OP must be a valid mathematical operation (*, +, %, etc). If B is a constant then it is applied to all elements in A. Vector B can be smaller than vector A in which case the elements of B are cyclically rotated through in the operation.
B - Input vector B. (Used only when a two vector operations are specified.)
C - Output vector C. (Used only when returning vector data.)
oA - Optional offset into vector A. Default is 0.
oB - Optional offset into vector B. Default is 0.
oC - Optional offset into vector C. Default is 0.
nA - Optional length of vector A. Default is 3.
nB - Optional length of vector B. Default is 3.
RETURN DEFINITION
rV - All constant values are returned through the procedure.
DESCRIPTION
TUvecMath performs vector specific operations on a single vector or between two vectors. If the the returned result is a vector then the result is returned in vector C otherwise it is returned through the routine. The offsets oA, oB, and oC allow arbitrary offsets into the input and output vectors from which the operations start. The input vector lengths are defaulted to 3 but can be changed through nA and nB. In general operations the lengths of the two vectors do not need to be identical but vector A must be the larger of the two. Vector C will have the same size as vector A.
ERRORS
None Generated
C BACKING
Yes
EXAMPLE(S)
# SET up three vectors
                                                                                
set A(0)  1.0 ; set A(1)  1.0 ; set A(2)  1.0
set B(0) -1.0 ; set B(1)  1.0 ; set B(2)  1.0
set C(0)  1.0 ; set C(1)  2.0 ; set C(2)  3.0
set C(3) -1.0 ; set C(4) -2.0 ; set C(5) -3.0
                                                                                
# TAKE cross product of A and C
                                                                                
TUvecMath A CROSS B D
puts stderr "A CROSS B : [format "%.1f %.1f %.1f" $D(0) $D(1) $D(2)]"
                                                                                
# TAKE dot product of A and C
                                                                                
set rV [TUvecMath A DOT B D]
puts stderr "A DOT B : [format "%.1f" $rV]"
# GET unit vector of first three components of C
                                                                                
TUvecMath C UNIT C D
puts stderr "C UNIT VECTOR : [format "%.1f %.1f %.1f" $D(0) $D(1) $D(2)]"
                                                                                
# ADD vector A to vector C
                                                                                
TUvecMath C + A D 0 0 0 6
puts stderr "C + A : [format "%.1f %.1f %.1f %.1f %.1f %.1f" \
               $D(0) $D(1) $D(2) $D(3) $D(4) $D(5)]"

> A CROSS B : 0.0 -2.0 2.0
> A DOT B : 1.0
> C UNIT VECTOR : 0.3 0.5 0.8
> C + A : 2.0 3.0 4.0 0.0 -1.0 -2.0

      
June 13, 2003