Previous Top Index Next

External 3D Vector Functions

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 */

VECINIT(attribute)

Initialize basic vectors, VecO, VecXo, VecYo, VecZo
CALL vecinit

Vec(vector,n)

return a vector component starting with base 0
Vec = "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 vector
say VecX(vec) /* 2.0 X component */

VecMake(x,y,z)

creates a vector from 3 numbers
say Vector(2.0,1.0,-3.0) /* "2.0 1.0 -3.0" */

VecNeg(vec)

returns the negative of a vector
say VecNeg("2.0 1.0 -3.0") /* "-2.0 -1.0 3.0" */

VecDot(a,b)

returns the dot (internal) product of two vectors
say VecDot("2.0 1.0 -3.0","1.0 0.0 -1.0") /* 5.0 */

VecLen(a,b)

returns the length of a vector
say VecLen("2.0 1.0 -3.0") /* 3.74 */

VecRnd()

returns a random vector of length 1 sampled isotropically in 4pi
say VecRnd() /* "-0.4588 -0.886 0.0615" */

VecAdd(a,b)
VecSub(a,b)

add or subtract 2 vector
say 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" */

VecComb(sa,A,sb,B)

Combine two vectors a and b with scaling. Return sa*A + sb*B

VecS(sa,A)

scale a vector. Return sa*A

VecAddS(sa,A,B)

Return sa*A+B

VecMult(A,B)

Multiply the components of each vector. Return the vector "Ax*Bx, Ay*By, Az*Bz"

VecCross(A,B)

Return the cross product of two vectors.
say VecCross("2.0 1.0 -3.0","1.0 0.0 -1.0") /* "-1 -1 -1" */

VecFormat(A,before,after)

Format through the FORMAT function a vector
say VecFormat("2.0 1.0 -3.0",2,3) /* "2.000 1.000 -3.000" */

Transformation Matrix Functions

All transformation matrices are defined as a 4x4 matrix, to allow also translation and scaling in one operation.

MatMake(vx,vy,vz)

Create a transformation 4x4 from 3 vectors
say MatMake(A,B,C) /* "Ax Ay Az 0 Bx By Bz 0 Cx Cy Cz 0 0 0 0 1" */

MatMake(mat,row,col)

Return a matrix element mat[row,col]

MatMake(mat,row,col,val)

Set a matrix element mat[row,col] = val

MatUnary()

Return a unary matrix

MatZero()

Return a zero matrix

MatXVec(mat,vec)

Return a vector the result of the multiplication of the matrix with the vector

MatT(mat)

Return the transpose matrix

MatRot(axis,angle)

Return a rotation matrix arround a specific axis X, Y or Z

MatTrans(vec)

Return a translation matrix

MatScale(scale|vector)

Return a scaling matrix

MatMult(a,b)

return a matrix the result of the multiplication of two matrices

MatPrint(mat,prefix,before,after,suffix)

print on screen a matrix
say 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|
		

MatInv(mat)

return the inverse of matrix mat


Previous Top Index Next