There are macros that you can use in your UDFs that will allow
you to perform operations such as computing the vector magnitude,
dot product, and cross product. For example, you can use the real function NV_MAG(V) to
compute the magnitude of vector V. Alternatively,
you can use the real function NV_MAG2(V) to obtain the square of the magnitude of
vector V.
The utility NV_MAG computes the magnitude
of a vector. This is taken as the square root of the sum of the squares
of the vector components.
NV_MAG(x) 2D: sqrt(x[0]*x[0] + x[1]*x[1]); 3D: sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
The utility NV_MAG2 computes the sum
of squares of vector components.
NV_MAG2(x) 2D: (x[0]*x[0] + x[1]*x[1]); 3D: (x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
See
DEFINE_DPM_BC
for an example
UDF that utilizes NV_MAG.
The following utilities compute the dot product of two sets of vector components.
ND_DOT(x, y, z, u, v, w) 2D: (x*u + y*v); 3D: (x*u + y*v + z*w); NV_DOT(x, u) 2D: (x[0]*u[0] + x[1]*u[1]); 3D: (x[0]*u[0] + x[1]*u[1] + x[2]*u[2]); NVD_DOT(x, u, v, w) 2D: (x[0]*u + x[1]*v); 3D: (x[0]*u + x[1]*v + x[2]*w);
See
DEFINE_DOM_SPECULAR_REFLECTIVITY
for an example UDF that utilizes NV_DOT.
For 3D, the CROSS macros return the
specified component of the vector cross product. For 2D, the macros
return the cross product of the vectors with the z-component of each vector set to 0.
ND_CROSS_X(x0,x1,x2,y0,y1,y2) 2D: 0.0 3D: (((x1)*(y2))-(y1)*(x2))) ND_CROSS_Y(x0,x1,x2,y0,y1,y2) 2D: 0.0 3D: (((x2)*(y0))-(y2)*(x0))) ND_CROSS_Z(x0,x1,x2,y0,y1,y2) 2D and 3D: (((x0)*(y1))-(y0)*(x1))) NV_CROSS_X(x,y) ND_CROSS_X(x[0],x[1],x[2],y[0],y[1],y[2]) NV_CROSS_Y(x,y) ND_CROSS_Y(x[0],x[1],x[2],y[0],y[1],y[2]) NV_CROSS_Z(x,y) ND_CROSS_Z(x[0],x[1],x[2],y[0],y[1],y[2]) NV_CROSS(a,x,y) a[0] = NV_CROSS_X(x,y); a[1] = NV_CROSS_Y(x,y); a[2] = NV_CROSS_Z(x,y);
See
DEFINE_GRID_MOTION
for an
example UDF that utilizes NV_CROSS.