Previous | Top | Index | Next |
The following routines are available after loading the
library file veclib.r with the command:
CALL import "veclib.r".
Both vectors and transformation matrix are represented as strings.
Vector="X Y Z" /* 3 word string */ Matrix4x4 = "xx xy xz tx yx yy yz ty ..." /* 16 word string */
Initialize basic vectors, VecO, VecXo, VecYo, VecZoCALL vecinit
return a vector component starting with base 0Vec = "2.0 1.0 -3.0"
say vec(Vec,0) /* 2.0 X component */
say vec(Vec,1) /* 1.0 Y component */
say vec(Vec,2) /* -3.0 Z component */
VecX(vector)
VecY(vector)
VecZ(vector)
return the X,Y or Z component of a vectorsay VecX(vec) /* 2.0 X component */
creates a vector from 3 numberssay Vector(2.0,1.0,-3.0) /* "2.0 1.0 -3.0" */
returns the negative of a vectorsay VecNeg("2.0 1.0 -3.0") /* "-2.0 -1.0 3.0" */
returns the dot (internal) product of two vectorssay VecDot("2.0 1.0 -3.0","1.0 0.0 -1.0") /* 5.0 */
returns the length of a vectorsay VecLen("2.0 1.0 -3.0") /* 3.74 */
returns a random vector of length 1 sampled isotropically in 4pisay VecRnd() /* "-0.4588 -0.886 0.0615" */
add or subtract 2 vectorsay VecAdd("2.0 1.0 -3.0","1.0 0.0 -1.0") /* "3.0 1.0 -4.0" */
say VecSub("2.0 1.0 -3.0","1.0 0.0 -1.0") /* "1.0 1.0 -2.0" */
Combine two vectors a and b with scaling. Return sa*A + sb*B
scale a vector. Return sa*A
Return sa*A+B
Multiply the components of each vector. Return the vector "Ax*Bx, Ay*By, Az*Bz"
Return the cross product of two vectors.say VecCross("2.0 1.0 -3.0","1.0 0.0 -1.0") /* "-1 -1 -1" */
Format through the FORMAT function a vectorsay VecFormat("2.0 1.0 -3.0",2,3) /* "2.000 1.000 -3.000" */
Create a transformation 4x4 from 3 vectorssay MatMake(A,B,C) /* "Ax Ay Az 0 Bx By Bz 0 Cx Cy Cz 0 0 0 0 1" */
Return a matrix element mat[row,col]
Set a matrix element mat[row,col] = val
Return a unary matrix
Return a zero matrix
Return a vector the result of the multiplication of the matrix with the vector
Return the transpose matrix
Return a rotation matrix arround a specific axis X, Y or Z
Return a translation matrix
Return a scaling matrix
return a matrix the result of the multiplication of two matrices
MatPrint(mat,prefix,before,after,suffix)
print on screen a matrixsay MatPrint(MatRot("X",1.0),"|",2,3,"|") /* Will print */| 1.000 0.000 0.000 0.000| | 0.000 0.540 -0.841 0.000| | 0.000 0.841 0.540 0.000| | 0.000 0.000 0.000 1.000|
return the inverse of matrix mat
Previous | Top | Index | Next |