Matrix/Vector/Quaternion Math
[libbn (numerical functions)]

Collaboration diagram for Matrix/Vector/Quaternion Math:

Files

file  vmath.h
 

vector/matrix math


file  mat.c
 

4 x 4 Matrix manipulation functions...


file  qmath.c
 

Quaternion math routines.


Defines

#define M_1_PI   0.31830988618379067153776752675
#define M_2_PI   0.63661977236758134307553505349
#define M_2_SQRTPI   1.12837916709551257389615890312
#define M_E   2.71828182845904523536028747135
#define M_EULER   0.57721566490153286060651209008
#define M_LOG2E   1.44269504088896340735992468100
#define M_LOG10E   0.43429448190325182765112891892
#define M_LN10   2.30258509299404568401799145468
#define M_LN2   0.69314718055994530941723212146
#define M_LNPI   1.14472988584940017414342735135
#define M_PI   3.14159265358979323846264338328
#define M_PI_2   1.57079632679489661923132169164
#define M_PI_4   0.78539816339744830966156608458
#define M_SQRT1_2   0.70710678118654752440084436210
#define M_SQRT2   1.41421356237309504880168872421
#define M_SQRT3   1.73205080756887729352744634151
#define M_SQRTPI   1.77245385090551602729816748334
#define DEG2RAD   0.017453292519943295769236907684
#define RAD2DEG   57.295779513082320876798154814105
#define VDIVIDE_TOL   (1.0e-20)
#define VUNITIZE_TOL   (1.0e-15)
#define ELEMENTS_PER_VECT2D   2
 # of fastf_t's per vect2d_t
#define ELEMENTS_PER_POINT2D   2
 # of fastf_t's per point2d_t
#define ELEMENTS_PER_VECT   3
 # of fastf_t's per vect_t
#define ELEMENTS_PER_POINT   3
 # of fastf_t's per point_t
#define ELEMENTS_PER_HVECT   4
 # of fastf_t's per hvect_t (homogeneous vector)
#define ELEMENTS_PER_HPOINT   4
 # of fastf_t's per hpt_t (homogeneous point)
#define ELEMENTS_PER_PLANE   4
 # of fastf_t's per plane_t
#define ELEMENTS_PER_MAT   (ELEMENTS_PER_PLANE*ELEMENTS_PER_PLANE)
 # of fastf_t's per mat_t
#define NEAR_ZERO(val, epsilon)   (((val) > -epsilon) && ((val) < epsilon))
#define VNEAR_ZERO(v, tol)
#define V2NEAR_ZERO(v, tol)   (NEAR_ZERO(v[X], tol) && NEAR_ZERO(v[Y], tol))
#define HNEAR_ZERO(v, tol)
#define ZERO(_a)   NEAR_ZERO((_a), SMALL_FASTF)
#define VZERO(_a)   VNEAR_ZERO((_a), SMALL_FASTF)
#define V2ZERO(_a)   V2NEAR_ZERO((_a), SMALL_FASTF)
#define HZERO(_a)   HNEAR_ZERO((_a), SMALL_FASTF)
#define NEAR_EQUAL(_a, _b, _tol)   NEAR_ZERO((_a) - (_b), (_tol))
#define VNEAR_EQUAL(_a, _b, _tol)
#define V2NEAR_EQUAL(a, b, tol)
#define HNEAR_EQUAL(_a, _b, _tol)
#define EQUAL(_a, _b)   NEAR_EQUAL((_a), (_b), SMALL_FASTF)
#define VEQUAL(_a, _b)   VNEAR_EQUAL((_a), (_b), SMALL_FASTF)
#define V2EQUAL(a, b)   ((a)[X]==(b)[X] && (a)[Y]==(b)[Y])
 Compare two vectors for EXACT equality. Use carefully. Version for degree 2 vectors. FIXME: no such thing as exact.
#define HEQUAL(a, b)   ((a)[X]==(b)[X] && (a)[Y]==(b)[Y] && (a)[Z]==(b)[Z] && (a)[W]==(b)[W])
 Compare two vectors for EXACT equality. Use carefully. Version for degree 4 vectors. FIXME: no such thing as exact.
#define CLAMP(_v, _l, _h)   if ((_v) < (_l)) _v = _l; else if ((_v) > (_h)) _v = _h
#define DIST_PT_PLANE(_pt, _pl)   (VDOT(_pt, _pl) - (_pl)[W])
 Compute distance from a point to a plane.
#define DIST_PT_PT_SQ(_a, _b)
 Compute distance between two points.
#define DIST_PT_PT(_a, _b)   sqrt(DIST_PT_PT_SQ(_a, _b))
#define MAT_DELTAS(_m, _x, _y, _z)
 set translation values of 4x4 matrix with x, y, z values.
#define MAT_DELTAS_VEC(_m, _v)   MAT_DELTAS(_m, (_v)[X], (_v)[Y], (_v)[Z])
 set translation values of 4x4 matrix from a vector.
#define MAT_DELTAS_VEC_NEG(_m, _v)   MAT_DELTAS(_m, -(_v)[X], -(_v)[Y], -(_v)[Z])
 set translation values of 4x4 matrix from a reversed vector.
#define MAT_DELTAS_GET(_v, _m)
 get translation values of 4x4 matrix to a vector.
#define MAT_DELTAS_GET_NEG(_v, _m)
 get translation values of 4x4 matrix to a vector, reversed.
#define MAT_DELTAS_ADD(_m, _x, _y, _z)
 increment translation elements in a 4x4 matrix with x, y, z values.
#define MAT_DELTAS_ADD_VEC(_m, _v)
 increment translation elements in a 4x4 matrix from a vector.
#define MAT_DELTAS_SUB(_m, _x, _y, _z)
 decrement translation elements in a 4x4 matrix with x, y, z values.
#define MAT_DELTAS_SUB_VEC(_m, _v)
 decrement translation elements in a 4x4 matrix from a vector.
#define MAT_DELTAS_MUL(_m, _x, _y, _z)
 decrement translation elements in a 4x4 matrix with x, y, z values.
#define MAT_DELTAS_MUL_VEC(_m, _v)
 decrement translation elements in a 4x4 matrix from a vector.
#define MAT_SCALE(_m, _x, _y, _z)
 set scale of 4x4 matrix from xyz.
#define MAT_SCALE_VEC(_m, _v)
 set scale of 4x4 matrix from vector.
#define MAT_SCALE_ALL(_m, _s)   (_m)[MSA] = (_s)
 set uniform scale of 4x4 matrix from scalar.
#define MAT_SCALE_ADD(_m, _x, _y, _z)
 add to scaling elements in a 4x4 matrix from xyz.
#define MAT_SCALE_ADD_VEC(_m, _v)
 add to scaling elements in a 4x4 matrix from vector.
#define MAT_SCALE_SUB(_m, _x, _y, _z)
 subtract from scaling elements in a 4x4 matrix from xyz.
#define MAT_SCALE_SUB_VEC(_m, _v)
 subtract from scaling elements in a 4x4 matrix from vector.
#define MAT_SCALE_MUL(_m, _x, _y, _z)
 multipy scaling elements in a 4x4 matrix from xyz.
#define MAT_SCALE_MUL_VEC(_m, _v)
 multiply scaling elements in a 4x4 matrix from vector.
#define MAT_ZERO(m)
 Zero a matrix.
#define MAT_IDN(m)
 Set matrix to identity.
#define MAT_TRANSPOSE(t, m)
 set t to the transpose of matrix m
#define MAT_COPY(d, s)
 Copy a matrix.
#define VSET(a, b, c, d)
 Set 3D vector at `a' to have coordinates `b', `c', and `d'.
#define V2SET(a, b, c)
 Set 2D vector at `a' to have coordinates `b' and `c'.
#define HSET(a, b, c, d, e)
 Set 4D vector at `a' to homogenous coordinates `b', `c', `d', and `e'.
#define VSETALL(a, s)
 Set all elements of 3D vector to same scalar value.
#define V2SETALL(a, s)
 Set 2D vector elements to same scalar value.
#define HSETALL(a, s)
 Set 4D vector elements to same scalar value.
#define VSETALLN(v, s, n)
 Set all elements of N-vector to same scalar value.
#define VMOVE(a, b)
 Transfer 3D vector at `b' to vector at `a'.
#define V2MOVE(a, b)
 Move a 2D vector.
#define HMOVE(a, b)
 Move a homogeneous 4-tuple.
#define VMOVEN(a, b, n)
 Transfer vector of length `n' at `b' to vector at `a'.
#define VREVERSE(a, b)
 Reverse the direction of 3D vector `b' and store it in `a'.
#define V2REVERSE(a, b)
 Reverse the direction of 2D vector `b' and store it in `a'.
#define HREVERSE(a, b)
 Same as VREVERSE, but for a 4-tuple. Also useful on plane_t objects.
#define VADD2(a, b, c)
 Add 3D vectors at `b' and `c', store result at `a'.
#define V2ADD2(a, b, c)
 Add 2D vectors at `b' and `c', store result at `a'.
#define HADD2(a, b, c)
 Add 4D vectors at `b' and `c', store result at `a'.
#define VADD2N(a, b, c, n)
 Add vectors of length `n' at `b' and `c', store result at `a'.
#define VSUB2(a, b, c)
 Subtract 3D vector at `c' from vector at `b', store result at `a'.
#define V2SUB2(a, b, c)
 Subtract 2D vector at `c' from vector at `b', store result at `a'.
#define HSUB2(a, b, c)
 Subtract 4D vector at `c' from vector at `b', store result at `a'.
#define VSUB2N(a, b, c, n)
 Subtract `n' length vector at `c' from vector at `b', store result at `a'.
#define VSUB3(a, b, c, d)
 3D Vectors: A = B - C - D
#define V2SUB3(a, b, c, d)
 2D Vectors: A = B - C - D
#define HSUB3(a, b, c, d)
 4D Vectors: A = B - C - D
#define VSUB3N(a, b, c, d, n)
 Vectors: A = B - C - D for vectors of length `n'.
#define VADD3(a, b, c, d)
 Add 3 3D vectors at `b', `c', and `d', store result at `a'.
#define V2ADD3(a, b, c, d)
 Add 3 2D vectors at `b', `c', and `d', store result at `a'.
#define HADD3(a, b, c, d)
 Add 3 4D vectors at `b', `c', and `d', store result at `a'.
#define VADD3N(a, b, c, d, n)
 Add 3 vectors of length `n' at `b', `c', and `d', store result at `a'.
#define VADD4(a, b, c, d, e)
 Add 4 vectors at `b', `c', `d', and `e', store result at `a'.
#define V2ADD4(a, b, c, d, e)
 Add 4 2D vectors at `b', `c', `d', and `e', store result at `a'.
#define HADD4(a, b, c, d, e)
 Add 4 4D vectors at `b', `c', `d', and `e', store result at `a'.
#define VADD4N(a, b, c, d, e, n)
 Add 4 `n' length vectors at `b', `c', `d', and `e', store result at `a'.
#define VSCALE(a, b, c)
 Scale 3D vector at `b' by scalar `c', store result at `a'.
#define V2SCALE(a, b, c)
 Scale 2D vector at `b' by scalar `c', store result at `a'.
#define HSCALE(a, b, c)
 Scale 4D vector at `b' by scalar `c', store result at `a'.
#define VSCALEN(a, b, c, n)
 Scale vector of length `n' at `b' by scalar `c', store result at `a'.
#define VUNITIZE(a)
 Normalize vector `a' to be a unit vector.
#define VUNITIZE_RET(a, ret)
 If vector magnitude is too small, return an error code.
#define VADD2SCALE(o, a, b, s)
 Find the sum of two points, and scale the result. Often used to find the midpoint.
#define VADD2SCALEN(o, a, b, n)
#define VSUB2SCALE(o, a, b, s)
 Find the difference between two points, and scale result. Often used to compute bounding sphere radius given rpp points.
#define VSUB2SCALEN(o, a, b, n)
#define VCOMB3(o, a, b, c, d, e, f)
 Combine together several vectors, scaled by a scalar.
#define VCOMB3N(o, a, b, c, d, e, f, n)
#define VCOMB2(o, a, b, c, d)
#define VCOMB2N(o, a, b, c, d, n)
#define VJOIN4(a, b, c, d, e, f, g, h, i, j)
#define VJOIN3(a, b, c, d, e, f, g, h)
#define VJOIN2(a, b, c, d, e, f)
 Compose 3D vector at `a' of: Vector at `b' plus scalar `c' times vector at `d' plus scalar `e' times vector at `f'.
#define V2JOIN2(a, b, c, d, e, f)
 Compose 2D vector at `a' of: Vector at `b' plus scalar `c' times vector at `d' plus scalar `e' times vector at `f'.
#define HJOIN2(a, b, c, d, e, f)
 Compose 4D vector at `a' of: Vector at `b' plus scalar `c' times vector at `d' plus scalar `e' times vector at `f'.
#define VJOIN2N(a, b, c, d, e, f, n)
#define VJOIN1(a, b, c, d)
#define V2JOIN1(a, b, c, d)
#define HJOIN1(a, b, c, d)
#define VJOIN1N(a, b, c, d, n)
#define VBLEND2(a, b, c, d, e)
 Blend into vector `a' scalar `b' times vector at `c' plus scalar `d' times vector at `e'.
#define VBLEND2N(a, b, c, d, e, n)
#define VPROJECT(a, b, c, d)
 Project vector `a' onto `b' vector `c' is the component of `a' parallel to `b' " `d' " " " " " orthogonal " ".
#define MAGSQ(a)   ((a)[X]*(a)[X] + (a)[Y]*(a)[Y] + (a)[Z]*(a)[Z])
 Return scalar magnitude squared of vector at `a'.
#define MAG2SQ(a)   ((a)[X]*(a)[X] + (a)[Y]*(a)[Y])
#define MAGNITUDE(a)   sqrt(MAGSQ(a))
 Return scalar magnitude of vector at `a'.
#define VCROSS(a, b, c)
 Store cross product of vectors at `b' and `c' in vector at `a'. Note that the "right hand rule" applies: If closing your right hand goes from `b' to `c', then your thumb points in the direction of the cross product.
#define VDOT(a, b)   ((a)[X]*(b)[X] + (a)[Y]*(b)[Y] + (a)[Z]*(b)[Z])
 Compute dot product of vectors at `a' and `b'.
#define V2DOT(a, b)   ((a)[X]*(b)[X] + (a)[Y]*(b)[Y])
#define HDOT(a, b)   ((a)[X]*(b)[X] + (a)[Y]*(b)[Y] + (a)[Z]*(b)[Z] + (a)[W]*(b)[W])
#define VSUB2DOT(_pt2, _pt, _vec)
 Subtract two points to make a vector, dot with another vector.
#define V2ARGS(a)   (a)[X], (a)[Y]
 Turn a vector into comma-separated list of elements, for subroutine args.
#define V3ARGS(a)   (a)[X], (a)[Y], (a)[Z]
#define V4ARGS(a)   (a)[X], (a)[Y], (a)[Z], (a)[W]
#define INTCLAMP(_a)   (NEAR_EQUAL((_a), rint(_a), VUNITIZE_TOL) ? (double)(long)rint(_a) : (_a))
#define V2INTCLAMPARGS(a)   INTCLAMP((a)[X]), INTCLAMP((a)[Y])
 integer clamped versions of the previous arg macros.
#define V3INTCLAMPARGS(a)   INTCLAMP((a)[X]), INTCLAMP((a)[Y]), INTCLAMP((a)[Z])
 integer clamped versions of the previous arg macros.
#define V4INTCLAMPARGS(a)   INTCLAMP((a)[X]), INTCLAMP((a)[Y]), INTCLAMP((a)[Z]), INTCLAMP((a)[W])
 integer clamped versions of the previous arg macros.
#define V2PRINT(a, b)   (void)fprintf(stderr, "%s (%g, %g)\n", a, V2ARGS(b));
 Print vector name and components on stderr.
#define VPRINT(a, b)   (void)fprintf(stderr, "%s (%g, %g, %g)\n", a, V3ARGS(b));
#define HPRINT(a, b)   (void)fprintf(stderr, "%s (%g, %g, %g, %g)\n", a, V4ARGS(b));
#define V2INTCLAMPPRINT(a, b)   (void)fprintf(stderr, "%s (%g, %g)\n", a, V2INTCLAMPARGS(b));
 Included below are integer clamped versions of the previous print macros.
#define VINTCLAMPPRINT(a, b)   (void)fprintf(stderr, "%s (%g, %g, %g)\n", a, V3INTCLAMPARGS(b));
#define HINTCLAMPPRINT(a, b)   (void)fprintf(stderr, "%s (%g, %g, %g, %g)\n", a, V4INTCLAMPARGS(b));
#define VELMUL(a, b, c)
 Vector element multiplication. Really: diagonal matrix X vect.
#define VELMUL3(a, b, c, d)
#define VELDIV(a, b, c)
 Similar to VELMUL.
#define VINVDIR(_inv, _dir)
 Given a direction vector, compute the inverses of each element. When division by zero would have occured, mark inverse as INFINITY.
#define MAT3X3VEC(o, mat, vec)
 Apply the 3x3 part of a mat_t to a 3-tuple. This rotates a vector without scaling it (changing its length).
#define VEC3X3MAT(o, i, m)
 Multiply a 3-tuple by the 3x3 part of a mat_t.
#define MAT3X2VEC(o, mat, vec)
 Apply the 3x3 part of a mat_t to a 2-tuple (Z part=0).
#define VEC2X3MAT(o, i, m)
 Multiply a 2-tuple (Z=0) by the 3x3 part of a mat_t.
#define MAT4X3PNT(o, m, i)
 Apply a 4x4 matrix to a 3-tuple which is an absolute Point in space. Output and input points should be separate arrays.
#define PNT3X4MAT(o, i, m)
 Multiply an Absolute 3-Point by a full 4x4 matrix. Output and input points should be separate arrays.
#define MAT4X4PNT(o, m, i)
 Multiply an Absolute hvect_t 4-Point by a full 4x4 matrix. Output and input points should be separate arrays.
#define MAT4X3VEC(o, m, i)
 Apply a 4x4 matrix to a 3-tuple which is a relative Vector in space. This macro can scale the length of the vector if [15] != 1.0. Output and input vectors should be separate arrays.
#define MAT4XSCALOR(o, m, i)
#define VEC3X4MAT(o, i, m)
 Multiply a Relative 3-Vector by most of a 4x4 matrix. Output and input vectors should be separate arrays.
#define VEC2X4MAT(o, i, m)
 Multiply a Relative 2-Vector by most of a 4x4 matrix.
#define BN_VEC_NON_UNIT_LEN(_vec)   (fabs(MAGSQ(_vec)) < 0.0001 || fabs(fabs(MAGSQ(_vec))-1) > 0.0001)
 Test a vector for non-unit length.
#define V_MIN(r, s)   if ((r) > (s)) r = (s)
 Included below are macros to update min and max X, Y, Z values to contain a point.
#define V_MAX(r, s)   if ((r) < (s)) r = (s)
#define VMIN(r, s)
#define VMAX(r, s)
#define VMINMAX(min, max, pt)
#define HDIVIDE(a, b)
 Divide out homogeneous parameter from hvect_t, creating vect_t.
#define VADD2_2D(a, b, c)   V2ADD2(a, b, c)
 Some 2-D versions of the 3-D macros given above.
#define VSUB2_2D(a, b, c)   V2SUB2(a, b, c)
#define MAGSQ_2D(a)   MAG2SQ(a)
#define VDOT_2D(a, b)   V2DOT(a, b)
#define VMOVE_2D(a, b)   V2MOVE(a, b)
#define VSCALE_2D(a, b, c)   V2SCALE(a, b, c)
#define VJOIN1_2D(a, b, c, d)   V2JOIN1(a, b, c, d)
#define QUAT_FROM_ROT(q, r, x, y, z)
 Quaternion math definitions.
#define QUAT_FROM_VROT(q, r, v)
#define QUAT_FROM_VROT_DEG(q, r, v)   QUAT_FROM_VROT(q, ((r)*(M_PI/180.0)), v)
#define QUAT_FROM_ROT_DEG(q, r, x, y, z)   QUAT_FROM_ROT(q, ((r)*(M_PI/180.0)), x, y, z)
#define QSET(a, b, c, d, e)
 Set quaternion at `a' to have coordinates `b', `c', `d', and `e'.
#define QMOVE(a, b)
 Transfer quaternion at `b' to quaternion at `a'.
#define QADD2(a, b, c)
 Add quaternions at `b' and `c', store result at `a'.
#define QSUB2(a, b, c)
 Subtract quaternion at `c' from quaternion at `b', store result at `a'.
#define QSCALE(a, b, c)
 Scale quaternion at `b' by scalar `c', store result at `a'.
#define QUNITIZE(a)
 Normalize quaternion 'a' to be a unit quaternion.
#define QMAGSQ(a)
 Return scalar magnitude squared of quaternion at `a'.
#define QMAGNITUDE(a)   sqrt(QMAGSQ(a))
 Return scalar magnitude of quaternion at `a'.
#define QDOT(a, b)
 Compute dot product of quaternions at `a' and `b'.
#define QMUL(a, b, c)
 Compute quaternion product a = b * c.
#define QCONJUGATE(a, b)
 Conjugate quaternion.
#define QINVERSE(a, b)
 Multiplicative inverse quaternion.
#define QBLEND2(a, b, c, d, e)
 Blend into quaternion `a'.
#define V3RPP_DISJOINT(_l1, _h1, _l2, _h2)
#define V3RPP_DISJOINT_TOL(_l1, _h1, _l2, _h2, _t)
#define V3RPP_OVERLAP(_l1, _h1, _l2, _h2)
#define V3RPP_OVERLAP_TOL(_l1, _h1, _l2, _h2, _t)
 If two extents overlap within distance tolerance, return true.
#define V3PT_IN_RPP(_pt, _lo, _hi)
 Is the point within or on the boundary of the RPP?
#define V3PT_IN_RPP_TOL(_pt, _lo, _hi, _t)
 Within the distance tolerance, is the point within the RPP?
#define V3PT_OUT_RPP_TOL(_pt, _lo, _hi, _t)
 Is the point outside the RPP by at least the distance tolerance? This will not return true if the point is on the RPP.
#define V3RPP1_IN_RPP2(_lo1, _hi1, _lo2, _hi2)
 Determine if one bounding box is within another. Also returns true if the boxes are the same.
#define V3DIR_FROM_AZEL(_d, _a, _e)
#define AZEL_FROM_V3DIR(_a, _e, _d)
#define VINITALL(_v)   {(_v), (_v), (_v)}
#define V2INITALL(_v)   {(_v), (_v), (_v)}
#define HINITALL(_v)   {(_v), (_v), (_v), (_v)}
#define VINIT_ZERO   {0.0, 0.0, 0.0}
#define V2INIT_ZERO   {0.0, 0.0}
#define HINIT_ZERO   {0.0, 0.0, 0.0, 0.0}
#define MAT_INIT_IDN   {1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}
#define MAT_INIT_ZERO   {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}

Typedefs

typedef fastf_t vect2d_t [ELEMENTS_PER_VECT2D]
 2-tuple vector
typedef fastf_t * vect2dp_t
 pointer to a 2-tuple vector
typedef fastf_t point2d_t [ELEMENTS_PER_POINT2D]
 2-tuple point
typedef fastf_t * point2dp_t
 pointer to a 2-tuple point
typedef fastf_t vect_t [ELEMENTS_PER_VECT]
 3-tuple vector
typedef fastf_t * vectp_t
 pointer to a 3-tuple vector
typedef fastf_t point_t [ELEMENTS_PER_POINT]
 3-tuple point
typedef fastf_t * pointp_t
 pointer to a 3-tuple point
typedef fastf_t hvect_t [ELEMENTS_PER_HVECT]
 4-tuple vector
typedef hvect_t quat_t
 4-element quaternion
typedef fastf_t hpoint_t [ELEMENTS_PER_HPOINT]
 4-tuple point
typedef fastf_t mat_t [ELEMENTS_PER_MAT]
 4x4 matrix
typedef fastf_t * matp_t
 pointer to a 4x4 matrix
typedef enum bn_vector_component_ bn_vector_component
typedef enum bn_matrix_component_ bn_matrix_component
typedef fastf_t plane_t [ELEMENTS_PER_PLANE]
 Definition of a plane equation.

Enumerations

enum  bn_vector_component_ {
  X = 0, Y = 1, Z = 2, H = 3,
  W = H
}
enum  bn_matrix_component_ {
  MSX = 0, MDX = 3, MSY = 5, MDY = 7,
  MSZ = 10, MDZ = 11, MSA = 15
}

Functions

void quat_mat2quat (quat_t quat, const mat_t mat)
void quat_quat2mat (mat_t mat, const quat_t quat)
double quat_distance (const quat_t q1, const quat_t q2)
void quat_double (quat_t qout, const quat_t q1, const quat_t q2)
void quat_bisect (quat_t qout, const quat_t q1, const quat_t q2)
void quat_slerp (quat_t qout, const quat_t q1, const quat_t q2, double f)
void quat_sberp (quat_t qout, const quat_t q1, const quat_t qa, const quat_t qb, const quat_t q2, double f)
void quat_make_nearest (quat_t q1, const quat_t q2)
void quat_print (const char *title, const quat_t quat)
void quat_exp (quat_t out, const quat_t in)
void quat_log (quat_t out, const quat_t in)
void quat_mat2quat (register fastf_t *quat, register const fastf_t *mat)
 Convert Matrix to Quaternion.
void quat_quat2mat (register fastf_t *mat, register const fastf_t *quat)
 Convert Quaternion to Matrix.
double quat_distance (const fastf_t *q1, const fastf_t *q2)
 Gives the euclidean distance between two quaternions.
void quat_double (fastf_t *qout, const fastf_t *q1, const fastf_t *q2)
 Gives the quaternion point representing twice the rotation from q1 to q2. Needed for patching Bezier curves together. A rather poor name admittedly.
void quat_bisect (fastf_t *qout, const fastf_t *q1, const fastf_t *q2)
 Gives the bisector of quaternions q1 and q2. (Could be done with quat_slerp and factor 0.5) [I believe they must be unit quaternions this to work].
void quat_slerp (fastf_t *qout, const fastf_t *q1, const fastf_t *q2, double f)
 Do Spherical Linear Interpolation between two unit quaternions by the given factor.
void quat_sberp (fastf_t *qout, const fastf_t *q1, const fastf_t *qa, const fastf_t *qb, const fastf_t *q2, double f)
 Spherical Bezier Interpolate between four quaternions by amount f. These are intended to be used as start and stop quaternions along with two control quaternions chosen to match spline segments with first order continuity.
void quat_make_nearest (fastf_t *q1, const fastf_t *q2)
 Set the quaternion q1 to the quaternion which yields the smallest rotation from q2 (of the two versions of q1 which produce the same orientation).
void quat_print (const char *title, const fastf_t *quat)
void quat_exp (fastf_t *out, const fastf_t *in)
 Exponentiate a quaternion, assuming that the scalar part is 0. Code by Ken Shoemake.
void quat_log (fastf_t *out, const fastf_t *in)
 Take the natural logarithm of a unit quaternion. Code by Ken Shoemake.

Detailed Description


Define Documentation

#define M_1_PI   0.31830988618379067153776752675

< 1/pi

Definition at line 95 of file vmath.h.

#define M_2_PI   0.63661977236758134307553505349

2/pi

Definition at line 98 of file vmath.h.

#define M_2_SQRTPI   1.12837916709551257389615890312

2/sqrt(pi)

Definition at line 101 of file vmath.h.

#define M_E   2.71828182845904523536028747135

e

Definition at line 104 of file vmath.h.

#define M_EULER   0.57721566490153286060651209008

Euler's constant

Definition at line 107 of file vmath.h.

#define M_LOG2E   1.44269504088896340735992468100

log_2(e)

Definition at line 110 of file vmath.h.

#define M_LOG10E   0.43429448190325182765112891892

log_10(e)

Definition at line 113 of file vmath.h.

#define M_LN10   2.30258509299404568401799145468

log_e(10)

Definition at line 116 of file vmath.h.

#define M_LN2   0.69314718055994530941723212146

log_e(2)

Definition at line 119 of file vmath.h.

#define M_LNPI   1.14472988584940017414342735135

log_e(pi)

Definition at line 122 of file vmath.h.

#define M_PI   3.14159265358979323846264338328
#define M_PI_2   1.57079632679489661923132169164

pi/2

Definition at line 128 of file vmath.h.

Referenced by bn_atan2().

#define M_PI_4   0.78539816339744830966156608458

pi/4

Definition at line 131 of file vmath.h.

#define M_SQRT1_2   0.70710678118654752440084436210

sqrt(1/2)

Definition at line 134 of file vmath.h.

#define M_SQRT2   1.41421356237309504880168872421

sqrt(2)

Definition at line 137 of file vmath.h.

#define M_SQRT3   1.73205080756887729352744634151

sqrt(3)

Definition at line 140 of file vmath.h.

#define M_SQRTPI   1.77245385090551602729816748334

sqrt(pi)

Definition at line 143 of file vmath.h.

#define DEG2RAD   0.017453292519943295769236907684

pi/180

Definition at line 147 of file vmath.h.

#define RAD2DEG   57.295779513082320876798154814105

180/pi

Definition at line 150 of file vmath.h.

Referenced by quat_print().

#define VDIVIDE_TOL   (1.0e-20)
#define VUNITIZE_TOL   (1.0e-15)

Definition at line 167 of file vmath.h.

Referenced by bn_coplanar(), main(), and mat2d_inverse().

#define ELEMENTS_PER_VECT2D   2

# of fastf_t's per vect2d_t

Definition at line 172 of file vmath.h.

#define ELEMENTS_PER_POINT2D   2

# of fastf_t's per point2d_t

Definition at line 175 of file vmath.h.

#define ELEMENTS_PER_VECT   3

# of fastf_t's per vect_t

Definition at line 178 of file vmath.h.

#define ELEMENTS_PER_POINT   3

# of fastf_t's per point_t

Definition at line 181 of file vmath.h.

#define ELEMENTS_PER_HVECT   4

# of fastf_t's per hvect_t (homogeneous vector)

Definition at line 184 of file vmath.h.

#define ELEMENTS_PER_HPOINT   4

# of fastf_t's per hpt_t (homogeneous point)

Definition at line 187 of file vmath.h.

#define ELEMENTS_PER_PLANE   4

# of fastf_t's per plane_t

Definition at line 190 of file vmath.h.

#define ELEMENTS_PER_MAT   (ELEMENTS_PER_PLANE*ELEMENTS_PER_PLANE)

# of fastf_t's per mat_t

Definition at line 193 of file vmath.h.

#define NEAR_ZERO ( val,
epsilon   )     (((val) > -epsilon) && ((val) < epsilon))

Return truthfully whether a value is within a specified epsilon distance from zero.

Definition at line 290 of file vmath.h.

Referenced by bn_aet_vec(), bn_coplanar(), bn_eigen2x2(), bn_isect_line2_line2(), bn_isect_line3_line3(), bn_isect_line_lseg(), bn_mat_angles(), bn_mat_ck(), bn_mat_is_equal(), bn_poly_quadratic_roots(), bn_poly_quartic_roots(), bn_vec_ortho(), and mat2d_inverse().

#define VNEAR_ZERO ( v,
tol   ) 
Value:
(NEAR_ZERO(v[X], tol) \
         && NEAR_ZERO(v[Y], tol) \
         && NEAR_ZERO(v[Z], tol))

Return truthfully whether all elements of a given vector are within a specified epsilon distance from zero.

Definition at line 296 of file vmath.h.

#define V2NEAR_ZERO ( v,
tol   )     (NEAR_ZERO(v[X], tol) && NEAR_ZERO(v[Y], tol))

Test for all elements of `v' being smaller than `tol'. Version for degree 2 vectors.

Definition at line 305 of file vmath.h.

#define HNEAR_ZERO ( v,
tol   ) 
Value:
(NEAR_ZERO(v[X], tol) \
     && NEAR_ZERO(v[Y], tol) \
     && NEAR_ZERO(v[Z], tol) \
     && NEAR_ZERO(h[W], tol))

Test for all elements of `v' being smaller than `tol'. Version for degree 2 vectors.

Definition at line 311 of file vmath.h.

#define ZERO ( _a   )     NEAR_ZERO((_a), SMALL_FASTF)
#define VZERO ( _a   )     VNEAR_ZERO((_a), SMALL_FASTF)

Return truthfully whether a vector is within a minimum representation tolerance from zero.

Use not recommended due to compilation-variant tolerance.

Definition at line 332 of file vmath.h.

#define V2ZERO ( _a   )     V2NEAR_ZERO((_a), SMALL_FASTF)

Return truthfully whether a 2d vector is within a minimum representation tolerance from zero.

Use not recommended due to compilation-variant tolerance.

Definition at line 340 of file vmath.h.

#define HZERO ( _a   )     HNEAR_ZERO((_a), SMALL_FASTF)

Return truthfully whether a homogenized 4-element vector is within a minimum representation tolerance from zero.

Use not recommended due to compilation-variant tolerance.

Definition at line 348 of file vmath.h.

#define NEAR_EQUAL ( _a,
_b,
_tol   )     NEAR_ZERO((_a) - (_b), (_tol))

Return truthfully whether two values are within a specified epsilon distance from each other.

Definition at line 355 of file vmath.h.

Referenced by bn_aet_vec(), bn_between(), bn_coplanar(), bn_dist_line3_line3(), bn_isect_line3_line3(), and main().

#define VNEAR_EQUAL ( _a,
_b,
_tol   ) 
Value:
(NEAR_EQUAL((_a)[X], (_b)[X], (_tol)) \
     && NEAR_EQUAL((_a)[Y], (_b)[Y], (_tol)) \
     && NEAR_EQUAL((_a)[Z], (_b)[Z], (_tol)))

Return truthfully whether two 3D vectors are approximately equal, within a specified absolute tolerance.

Definition at line 361 of file vmath.h.

#define V2NEAR_EQUAL ( a,
b,
tol   ) 
Value:
(NEAR_EQUAL((a)[X], (b)[X], tol) \
     && NEAR_EQUAL((a)[Y], (b)[Y], tol))

Return truthfully whether two 2D vectors are approximately equal, within a specified absolute tolerance.

Definition at line 370 of file vmath.h.

#define HNEAR_EQUAL ( _a,
_b,
_tol   ) 
Value:
(NEAR_EQUAL((_a)[X], (_b)[X], (_tol)) \
     && NEAR_EQUAL((_a)[Y], (_b)[Y], (_tol)) \
     && NEAR_EQUAL((_a)[Z], (_b)[Z], (_tol)) \
     && NEAR_EQUAL((_a)[W], (_b)[W], (_tol)))

Return truthfully whether two 4D vectors are approximately equal, within a specified absolute tolerance.

Definition at line 378 of file vmath.h.

#define EQUAL ( _a,
_b   )     NEAR_EQUAL((_a), (_b), SMALL_FASTF)

Return truthfully whether two values are within a minimum representation tolerance from each other.

Use not recommended due to compilation-variant tolerance.

Definition at line 390 of file vmath.h.

#define VEQUAL ( _a,
_b   )     VNEAR_EQUAL((_a), (_b), SMALL_FASTF)

Return truthfully whether two vectors are equal within a minimum representation tolerance.

Use not recommended due to compilation-variant tolerance.

Definition at line 399 of file vmath.h.

#define V2EQUAL ( a,
 )     ((a)[X]==(b)[X] && (a)[Y]==(b)[Y])

Compare two vectors for EXACT equality. Use carefully. Version for degree 2 vectors. FIXME: no such thing as exact.

Definition at line 405 of file vmath.h.

#define HEQUAL ( a,
 )     ((a)[X]==(b)[X] && (a)[Y]==(b)[Y] && (a)[Z]==(b)[Z] && (a)[W]==(b)[W])

Compare two vectors for EXACT equality. Use carefully. Version for degree 4 vectors. FIXME: no such thing as exact.

Definition at line 411 of file vmath.h.

#define CLAMP ( _v,
_l,
_h   )     if ((_v) < (_l)) _v = _l; else if ((_v) > (_h)) _v = _h

clamp a value to a low/high number.

Definition at line 417 of file vmath.h.

#define DIST_PT_PLANE ( _pt,
_pl   )     (VDOT(_pt, _pl) - (_pl)[W])

Compute distance from a point to a plane.

Definition at line 421 of file vmath.h.

#define DIST_PT_PT_SQ ( _a,
_b   ) 
Value:
((_a)[X]-(_b)[X])*((_a)[X]-(_b)[X]) + \
        ((_a)[Y]-(_b)[Y])*((_a)[Y]-(_b)[Y]) + \
        ((_a)[Z]-(_b)[Z])*((_a)[Z]-(_b)[Z])

Compute distance between two points.

Definition at line 424 of file vmath.h.

#define DIST_PT_PT ( _a,
_b   )     sqrt(DIST_PT_PT_SQ(_a, _b))

Definition at line 428 of file vmath.h.

#define MAT_DELTAS ( _m,
_x,
_y,
_z   ) 
Value:
{ \
        (_m)[MDX] = (_x); \
        (_m)[MDY] = (_y); \
        (_m)[MDZ] = (_z); \
}

set translation values of 4x4 matrix with x, y, z values.

Definition at line 431 of file vmath.h.

#define MAT_DELTAS_VEC ( _m,
_v   )     MAT_DELTAS(_m, (_v)[X], (_v)[Y], (_v)[Z])

set translation values of 4x4 matrix from a vector.

Definition at line 438 of file vmath.h.

Referenced by bn_mat_scale_about_pt(), bn_mat_xform_about_pt(), bn_vlist_3string(), tp_3axis(), and tp_3symbol().

#define MAT_DELTAS_VEC_NEG ( _m,
_v   )     MAT_DELTAS(_m, -(_v)[X], -(_v)[Y], -(_v)[Z])

set translation values of 4x4 matrix from a reversed vector.

Definition at line 445 of file vmath.h.

Referenced by bn_mat_scale_about_pt(), bn_mat_xform_about_pt(), and bn_wrt_point_direc().

#define MAT_DELTAS_GET ( _v,
_m   ) 
Value:
{ \
        (_v)[X] = (_m)[MDX]; \
        (_v)[Y] = (_m)[MDY]; \
        (_v)[Z] = (_m)[MDZ]; \
}

get translation values of 4x4 matrix to a vector.

Definition at line 449 of file vmath.h.

#define MAT_DELTAS_GET_NEG ( _v,
_m   ) 
Value:
{ \
        (_v)[X] = -(_m)[MDX]; \
        (_v)[Y] = -(_m)[MDY]; \
        (_v)[Z] = -(_m)[MDZ]; \
}

get translation values of 4x4 matrix to a vector, reversed.

Definition at line 459 of file vmath.h.

#define MAT_DELTAS_ADD ( _m,
_x,
_y,
_z   ) 
Value:
{ \
        (_m)[MDX] += (_x); \
        (_m)[MDY] += (_y); \
        (_m)[MDZ] += (_z); \
}

increment translation elements in a 4x4 matrix with x, y, z values.

Definition at line 469 of file vmath.h.

#define MAT_DELTAS_ADD_VEC ( _m,
_v   ) 
Value:
{ \
        (_m)[MDX] += (_v)[X]; \
        (_m)[MDY] += (_v)[Y]; \
        (_m)[MDZ] += (_v)[Z]; \
}

increment translation elements in a 4x4 matrix from a vector.

Definition at line 479 of file vmath.h.

#define MAT_DELTAS_SUB ( _m,
_x,
_y,
_z   ) 
Value:
{ \
        (_m)[MDX] -= (_x); \
        (_m)[MDY] -= (_y); \
        (_m)[MDZ] -= (_z); \
}

decrement translation elements in a 4x4 matrix with x, y, z values.

Definition at line 489 of file vmath.h.

#define MAT_DELTAS_SUB_VEC ( _m,
_v   ) 
Value:
{ \
        (_m)[MDX] -= (_v)[X]; \
        (_m)[MDY] -= (_v)[Y]; \
        (_m)[MDZ] -= (_v)[Z]; \
}

decrement translation elements in a 4x4 matrix from a vector.

Definition at line 499 of file vmath.h.

#define MAT_DELTAS_MUL ( _m,
_x,
_y,
_z   ) 
Value:
{ \
        (_m)[MDX] *= (_x); \
        (_m)[MDY] *= (_y); \
        (_m)[MDZ] *= (_z); \
}

decrement translation elements in a 4x4 matrix with x, y, z values.

Definition at line 509 of file vmath.h.

#define MAT_DELTAS_MUL_VEC ( _m,
_v   ) 
Value:
{ \
        (_m)[MDX] *= (_v)[X]; \
        (_m)[MDY] *= (_v)[Y]; \
        (_m)[MDZ] *= (_v)[Z]; \
}

decrement translation elements in a 4x4 matrix from a vector.

Definition at line 519 of file vmath.h.

#define MAT_SCALE ( _m,
_x,
_y,
_z   ) 
Value:
{ \
        (_m)[MSX] = _x; \
        (_m)[MSY] = _y; \
        (_m)[MSZ] = _z; \
}

set scale of 4x4 matrix from xyz.

Definition at line 526 of file vmath.h.

#define MAT_SCALE_VEC ( _m,
_v   ) 
Value:
{ \
        (_m)[MSX] = (_v)[X]; \
        (_m)[MSY] = (_v)[Y]; \
        (_m)[MSZ] = (_v)[Z]; \
}

set scale of 4x4 matrix from vector.

Definition at line 533 of file vmath.h.

#define MAT_SCALE_ALL ( _m,
_s   )     (_m)[MSA] = (_s)

set uniform scale of 4x4 matrix from scalar.

Definition at line 540 of file vmath.h.

#define MAT_SCALE_ADD ( _m,
_x,
_y,
_z   ) 
Value:
{ \
        (_m)[MSX] += _x; \
        (_m)[MSY] += _y; \
        (_m)[MSZ] += _z; \
}

add to scaling elements in a 4x4 matrix from xyz.

Definition at line 543 of file vmath.h.

#define MAT_SCALE_ADD_VEC ( _m,
_v   ) 
Value:
{ \
        (_m)[MSX] += (_v)[X]; \
        (_m)[MSY] += (_v)[Y]; \
        (_m)[MSZ] += (_v)[Z]; \
}

add to scaling elements in a 4x4 matrix from vector.

Definition at line 550 of file vmath.h.

#define MAT_SCALE_SUB ( _m,
_x,
_y,
_z   ) 
Value:
{ \
        (_m)[MSX] -= _x; \
        (_m)[MSY] -= _y; \
        (_m)[MSZ] -= _z; \
}

subtract from scaling elements in a 4x4 matrix from xyz.

Definition at line 557 of file vmath.h.

#define MAT_SCALE_SUB_VEC ( _m,
_v   ) 
Value:
{ \
        (_m)[MSX] -= (_v)[X]; \
        (_m)[MSY] -= (_v)[Y]; \
        (_m)[MSZ] -= (_v)[Z]; \
}

subtract from scaling elements in a 4x4 matrix from vector.

Definition at line 567 of file vmath.h.

#define MAT_SCALE_MUL ( _m,
_x,
_y,
_z   ) 
Value:
{ \
        (_m)[MSX] *= _x; \
        (_m)[MSY] *= _y; \
        (_m)[MSZ] *= _z; \
}

multipy scaling elements in a 4x4 matrix from xyz.

Definition at line 574 of file vmath.h.

#define MAT_SCALE_MUL_VEC ( _m,
_v   ) 
Value:
{ \
        (_m)[MSX] *= (_v)[X]; \
        (_m)[MSY] *= (_v)[Y]; \
        (_m)[MSZ] *= (_v)[Z]; \
}

multiply scaling elements in a 4x4 matrix from vector.

Definition at line 581 of file vmath.h.

#define MAT_ZERO (  ) 
Value:
{ \
        (m)[0] = (m)[1] = (m)[2] = (m)[3] = \
        (m)[4] = (m)[5] = (m)[6] = (m)[7] = \
        (m)[8] = (m)[9] = (m)[10] = (m)[11] = \
        (m)[12] = (m)[13] = (m)[14] = (m)[15] = 0.0; \
}

Zero a matrix.

In following are macro versions of librt/mat.c functions for when speed really matters.

Definition at line 595 of file vmath.h.

Referenced by bn_isect_planes(), and bn_mat_scale_about_pt().

#define MAT_IDN (  ) 
Value:
{ \
        (m)[1] = (m)[2] = (m)[3] = (m)[4] = \
        (m)[6] = (m)[7] = (m)[8] = (m)[9] = \
        (m)[11] = (m)[12] = (m)[13] = (m)[14] = 0.0; \
        (m)[0] = (m)[5] = (m)[10] = (m)[15] = 1.0; \
}

Set matrix to identity.

Definition at line 603 of file vmath.h.

Referenced by bn_decode_mat(), bn_mat_angles(), bn_mat_angles_rad(), bn_mat_arb_rot(), bn_mat_fromto(), bn_mat_lookat(), bn_mat_scale_about_pt(), bn_mat_xform_about_pt(), bn_vlist_3string(), bn_wrt_point_direc(), PL_FORTRAN(), tp_3axis(), tp_3marker(), and tp_3symbol().

#define MAT_TRANSPOSE ( t,
 ) 
Value:
{ \
        (t)[0] = (m)[0]; \
        (t)[4] = (m)[1]; \
        (t)[8] = (m)[2]; \
        (t)[12] = (m)[3]; \
        (t)[1] = (m)[4]; \
        (t)[5] = (m)[5]; \
        (t)[9] = (m)[6]; \
        (t)[13] = (m)[7]; \
        (t)[2] = (m)[8]; \
        (t)[6] = (m)[9]; \
        (t)[10] = (m)[10]; \
        (t)[14] = (m)[11]; \
        (t)[3] = (m)[12]; \
        (t)[7] = (m)[13]; \
        (t)[11] = (m)[14]; \
        (t)[15] = (m)[15]; \
}

set t to the transpose of matrix m

Definition at line 611 of file vmath.h.

Referenced by bn_mat_trn().

#define MAT_COPY ( d,
 ) 
Value:
{ \
        (d)[0] = (s)[0]; \
        (d)[1] = (s)[1]; \
        (d)[2] = (s)[2]; \
        (d)[3] = (s)[3]; \
        (d)[4] = (s)[4]; \
        (d)[5] = (s)[5]; \
        (d)[6] = (s)[6]; \
        (d)[7] = (s)[7]; \
        (d)[8] = (s)[8]; \
        (d)[9] = (s)[9]; \
        (d)[10] = (s)[10]; \
        (d)[11] = (s)[11]; \
        (d)[12] = (s)[12]; \
        (d)[13] = (s)[13]; \
        (d)[14] = (s)[14]; \
        (d)[15] = (s)[15]; \
}

Copy a matrix.

Definition at line 631 of file vmath.h.

Referenced by bn_mat_inverse(), bn_mat_lookat(), and bn_mat_mul2().

#define VSET ( a,
b,
c,
 ) 
#define V2SET ( a,
b,
c   ) 
Value:
{ \
        (a)[X] = (b); \
        (a)[Y] = (c); \
}

Set 2D vector at `a' to have coordinates `b' and `c'.

Definition at line 658 of file vmath.h.

#define HSET ( a,
b,
c,
d,
 ) 
Value:
{ \
        (a)[X] = (b); \
        (a)[Y] = (c); \
        (a)[Z] = (d); \
        (a)[H] = (e); \
}

Set 4D vector at `a' to homogenous coordinates `b', `c', `d', and `e'.

Definition at line 664 of file vmath.h.

#define VSETALL ( a,
 ) 
Value:
{ \
        (a)[X] = (a)[Y] = (a)[Z] = (s); \
}

Set all elements of 3D vector to same scalar value.

Definition at line 673 of file vmath.h.

Referenced by bn_cmd_noise_slice(), bn_isect_2planes(), bn_math_cmd(), bn_vec_ortho(), and bn_vec_perp().

#define V2SETALL ( a,
 ) 
Value:
{ \
        (a)[X] = (a)[Y] = (s); \
}

Set 2D vector elements to same scalar value.

Definition at line 678 of file vmath.h.

#define HSETALL ( a,
 ) 
Value:
{ \
        (a)[X] = (a)[Y] = (a)[Z] = (a)[H] = (s); \
}

Set 4D vector elements to same scalar value.

Definition at line 683 of file vmath.h.

#define VSETALLN ( v,
s,
n   ) 
Value:
{ \
        register int _j; \
        for (_j=0; _j<n; _j++) v[_j]=(s); \
}

Set all elements of N-vector to same scalar value.

Definition at line 689 of file vmath.h.

#define VMOVE ( a,
 ) 
#define V2MOVE ( a,
 ) 
Value:
{ \
        (a)[X] = (b)[X]; \
        (a)[Y] = (b)[Y]; \
}

Move a 2D vector.

Definition at line 703 of file vmath.h.

Referenced by bn_dist_pt2_lseg2().

#define HMOVE ( a,
 ) 
Value:
{ \
        (a)[X] = (b)[X]; \
        (a)[Y] = (b)[Y]; \
        (a)[Z] = (b)[Z]; \
        (a)[W] = (b)[W]; \
}

Move a homogeneous 4-tuple.

Definition at line 709 of file vmath.h.

#define VMOVEN ( a,
b,
n   ) 
Value:
{ \
        register int _vmove; \
        for (_vmove = 0; _vmove < (n); _vmove++) { \
                (a)[_vmove] = (b)[_vmove]; \
        } \
}

Transfer vector of length `n' at `b' to vector at `a'.

Definition at line 717 of file vmath.h.

#define VREVERSE ( a,
 ) 
Value:
{ \
        (a)[X] = -(b)[X]; \
        (a)[Y] = -(b)[Y]; \
        (a)[Z] = -(b)[Z]; \
}

Reverse the direction of 3D vector `b' and store it in `a'.

Definition at line 726 of file vmath.h.

Referenced by bn_isect_2planes().

#define V2REVERSE ( a,
 ) 
Value:
{ \
        (a)[X] = -(b)[X]; \
        (a)[Y] = -(b)[Y]; \
}

Reverse the direction of 2D vector `b' and store it in `a'.

Definition at line 733 of file vmath.h.

#define HREVERSE ( a,
 ) 
Value:
{ \
        (a)[X] = -(b)[X]; \
        (a)[Y] = -(b)[Y]; \
        (a)[Z] = -(b)[Z]; \
        (a)[W] = -(b)[W]; \
}

Same as VREVERSE, but for a 4-tuple. Also useful on plane_t objects.

Definition at line 742 of file vmath.h.

#define VADD2 ( a,
b,
c   ) 
Value:
{ \
        (a)[X] = (b)[X] + (c)[X]; \
        (a)[Y] = (b)[Y] + (c)[Y]; \
        (a)[Z] = (b)[Z] + (c)[Z]; \
}

Add 3D vectors at `b' and `c', store result at `a'.

Definition at line 750 of file vmath.h.

Referenced by bn_isect_line3_line3(), and tp_3axis().

#define V2ADD2 ( a,
b,
c   ) 
Value:
{ \
        (a)[X] = (b)[X] + (c)[X]; \
        (a)[Y] = (b)[Y] + (c)[Y]; \
}

Add 2D vectors at `b' and `c', store result at `a'.

Definition at line 757 of file vmath.h.

#define HADD2 ( a,
b,
c   ) 
Value:
{ \
        (a)[X] = (b)[X] + (c)[X]; \
        (a)[Y] = (b)[Y] + (c)[Y]; \
        (a)[Z] = (b)[Z] + (c)[Z]; \
        (a)[W] = (b)[W] + (c)[W]; \
}

Add 4D vectors at `b' and `c', store result at `a'.

Definition at line 763 of file vmath.h.

#define VADD2N ( a,
b,
c,
n   ) 
Value:
{ \
        register int _vadd2; \
        for (_vadd2 = 0; _vadd2 < (n); _vadd2++) { \
                (a)[_vadd2] = (b)[_vadd2] + (c)[_vadd2]; \
        } \
}

Add vectors of length `n' at `b' and `c', store result at `a'.

Definition at line 774 of file vmath.h.

Referenced by anim_quat2mat().

#define VSUB2 ( a,
b,
c   ) 
#define V2SUB2 ( a,
b,
c   ) 
Value:
{ \
        (a)[X] = (b)[X] - (c)[X]; \
        (a)[Y] = (b)[Y] - (c)[Y]; \
}

Subtract 2D vector at `c' from vector at `b', store result at `a'.

Definition at line 796 of file vmath.h.

#define HSUB2 ( a,
b,
c   ) 
Value:
{ \
        (a)[X] = (b)[X] - (c)[X]; \
        (a)[Y] = (b)[Y] - (c)[Y]; \
        (a)[Z] = (b)[Z] - (c)[Z]; \
        (a)[W] = (b)[W] - (c)[W]; \
}

Subtract 4D vector at `c' from vector at `b', store result at `a'.

Definition at line 805 of file vmath.h.

#define VSUB2N ( a,
b,
c,
n   ) 
Value:
{ \
        register int _vsub2; \
        for (_vsub2 = 0; _vsub2 < (n); _vsub2++) { \
                (a)[_vsub2] = (b)[_vsub2] - (c)[_vsub2]; \
        } \
}

Subtract `n' length vector at `c' from vector at `b', store result at `a'.

Definition at line 816 of file vmath.h.

#define VSUB3 ( a,
b,
c,
 ) 
Value:
{ \
        (a)[X] = (b)[X] - (c)[X] - (d)[X]; \
        (a)[Y] = (b)[Y] - (c)[Y] - (d)[Y]; \
        (a)[Z] = (b)[Z] - (c)[Z] - (d)[Z]; \
}

3D Vectors: A = B - C - D

Definition at line 825 of file vmath.h.

#define V2SUB3 ( a,
b,
c,
 ) 
Value:
{ \
        (a)[X] = (b)[X] - (c)[X] - (d)[X]; \
        (a)[Y] = (b)[Y] - (c)[Y] - (d)[Y]; \
}

2D Vectors: A = B - C - D

Definition at line 832 of file vmath.h.

#define HSUB3 ( a,
b,
c,
 ) 
Value:
{ \
        (a)[X] = (b)[X] - (c)[X] - (d)[X]; \
        (a)[Y] = (b)[Y] - (c)[Y] - (d)[Y]; \
        (a)[Z] = (b)[Z] - (c)[Z] - (d)[Z]; \
        (a)[W] = (b)[W] - (c)[W] - (d)[W]; \
}

4D Vectors: A = B - C - D

Definition at line 838 of file vmath.h.

#define VSUB3N ( a,
b,
c,
d,
n   ) 
Value:
{ \
        register int _vsub3; \
        for (_vsub3 = 0; _vsub3 < (n); _vsub3++) { \
                (a)[_vsub3] = (b)[_vsub3] - (c)[_vsub3] - (d)[_vsub3]; \
        } \
}

Vectors: A = B - C - D for vectors of length `n'.

Definition at line 846 of file vmath.h.

#define VADD3 ( a,
b,
c,
 ) 
Value:
{ \
        (a)[X] = (b)[X] + (c)[X] + (d)[X]; \
        (a)[Y] = (b)[Y] + (c)[Y] + (d)[Y]; \
        (a)[Z] = (b)[Z] + (c)[Z] + (d)[Z]; \
}

Add 3 3D vectors at `b', `c', and `d', store result at `a'.

Definition at line 855 of file vmath.h.

Referenced by tp_3vector().

#define V2ADD3 ( a,
b,
c,
 ) 
Value:
{ \
        (a)[X] = (b)[X] + (c)[X] + (d)[X]; \
        (a)[Y] = (b)[Y] + (c)[Y] + (d)[Y]; \
}

Add 3 2D vectors at `b', `c', and `d', store result at `a'.

Definition at line 862 of file vmath.h.

#define HADD3 ( a,
b,
c,
 ) 
Value:
{ \
        (a)[X] = (b)[X] + (c)[X] + (d)[X]; \
        (a)[Y] = (b)[Y] + (c)[Y] + (d)[Y]; \
        (a)[Z] = (b)[Z] + (c)[Z] + (d)[Z]; \
        (a)[W] = (b)[W] + (c)[W] + (d)[W]; \
}

Add 3 4D vectors at `b', `c', and `d', store result at `a'.

Definition at line 868 of file vmath.h.

#define VADD3N ( a,
b,
c,
d,
n   ) 
Value:
{ \
        register int _vadd3; \
        for (_vadd3 = 0; _vadd3 < (n); _vadd3++) { \
                (a)[_vadd3] = (b)[_vadd3] + (c)[_vadd3] + (d)[_vadd3]; \
        } \
}

Add 3 vectors of length `n' at `b', `c', and `d', store result at `a'.

Definition at line 879 of file vmath.h.

#define VADD4 ( a,
b,
c,
d,
 ) 
Value:
{ \
        (a)[X] = (b)[X] + (c)[X] + (d)[X] + (e)[X]; \
        (a)[Y] = (b)[Y] + (c)[Y] + (d)[Y] + (e)[Y]; \
        (a)[Z] = (b)[Z] + (c)[Z] + (d)[Z] + (e)[Z]; \
}

Add 4 vectors at `b', `c', `d', and `e', store result at `a'.

Definition at line 891 of file vmath.h.

#define V2ADD4 ( a,
b,
c,
d,
 ) 
Value:
{ \
        (a)[X] = (b)[X] + (c)[X] + (d)[X] + (e)[X]; \
        (a)[Y] = (b)[Y] + (c)[Y] + (d)[Y] + (e)[Y]; \
}

Add 4 2D vectors at `b', `c', `d', and `e', store result at `a'.

Definition at line 901 of file vmath.h.

#define HADD4 ( a,
b,
c,
d,
 ) 
Value:
{ \
        (a)[X] = (b)[X] + (c)[X] + (d)[X] + (e)[X]; \
        (a)[Y] = (b)[Y] + (c)[Y] + (d)[Y] + (e)[Y]; \
        (a)[Z] = (b)[Z] + (c)[Z] + (d)[Z] + (e)[Z]; \
        (a)[W] = (b)[W] + (c)[W] + (d)[W] + (e)[W]; \
}

Add 4 4D vectors at `b', `c', `d', and `e', store result at `a'.

Definition at line 910 of file vmath.h.

#define VADD4N ( a,
b,
c,
d,
e,
n   ) 
Value:
{ \
        register int _vadd4; \
        for (_vadd4 = 0; _vadd4 < (n); _vadd4++) { \
                (a)[_vadd4] = (b)[_vadd4] + (c)[_vadd4] + (d)[_vadd4] + (e)[_vadd4]; \
        } \
}

Add 4 `n' length vectors at `b', `c', `d', and `e', store result at `a'.

Definition at line 921 of file vmath.h.

#define VSCALE ( a,
b,
c   ) 
Value:
{ \
        (a)[X] = (b)[X] * (c); \
        (a)[Y] = (b)[Y] * (c); \
        (a)[Z] = (b)[Z] * (c); \
}

Scale 3D vector at `b' by scalar `c', store result at `a'.

Definition at line 930 of file vmath.h.

Referenced by bn_coplanar(), bn_dist_line3_lseg3(), bn_distsq_line3_line3(), bn_htov_move(), bn_isect_line3_line3(), bn_isect_line_lseg(), bn_isect_pt_lseg(), bn_mk_plane_3pts(), bn_rotate_plane(), quat_exp(), quat_log(), tp_3axis(), and tp_3vector().

#define V2SCALE ( a,
b,
c   ) 
Value:
{ \
        (a)[X] = (b)[X] * (c); \
        (a)[Y] = (b)[Y] * (c); \
}

Scale 2D vector at `b' by scalar `c', store result at `a'.

Definition at line 937 of file vmath.h.

#define HSCALE ( a,
b,
c   ) 
Value:
{ \
        (a)[X] = (b)[X] * (c); \
        (a)[Y] = (b)[Y] * (c); \
        (a)[Z] = (b)[Z] * (c); \
        (a)[W] = (b)[W] * (c); \
}

Scale 4D vector at `b' by scalar `c', store result at `a'.

Definition at line 943 of file vmath.h.

#define VSCALEN ( a,
b,
c,
n   ) 
Value:
{ \
        register int _vscale; \
        for (_vscale = 0; _vscale < (n); _vscale++) { \
                (a)[_vscale] = (b)[_vscale] * (c); \
        } \
}

Scale vector of length `n' at `b' by scalar `c', store result at `a'.

Definition at line 954 of file vmath.h.

#define VUNITIZE (  ) 
Value:
{ \
        register double _f = MAGSQ(a); \
        if (! NEAR_EQUAL(_f, 1.0, VUNITIZE_TOL)) { \
                _f = sqrt(_f); \
                if (_f < VDIVIDE_TOL) { \
                        VSETALL((a), 0.0); \
                } else { \
                        _f = 1.0/_f; \
                        (a)[X] *= _f; (a)[Y] *= _f; (a)[Z] *= _f; \
                } \
        } \
}

Normalize vector `a' to be a unit vector.

Definition at line 962 of file vmath.h.

Referenced by bn_aet_vec(), bn_dist_pt3_line3(), bn_does_ray_isect_tri(), bn_eigen2x2(), bn_isect_line2_line2(), bn_isect_line3_plane(), bn_isect_line_lseg(), bn_mat_fromto(), bn_vec_ae(), and quat_print().

#define VUNITIZE_RET ( a,
ret   ) 
Value:
{ \
        register double _f; \
        _f = MAGNITUDE(a); \
        if (_f < VDIVIDE_TOL) return ret; \
        _f = 1.0/_f; \
        (a)[X] *= _f; (a)[Y] *= _f; (a)[Z] *= _f; \
}

If vector magnitude is too small, return an error code.

Definition at line 976 of file vmath.h.

#define VADD2SCALE ( o,
a,
b,
 ) 
Value:
{ \
                        (o)[X] = ((a)[X] + (b)[X]) * (s); \
                        (o)[Y] = ((a)[Y] + (b)[Y]) * (s); \
                        (o)[Z] = ((a)[Z] + (b)[Z]) * (s); \
}

Find the sum of two points, and scale the result. Often used to find the midpoint.

Definition at line 988 of file vmath.h.

#define VADD2SCALEN ( o,
a,
b,
n   ) 
Value:
{ \
        register int _vadd2scale; \
        for (_vadd2scale = 0; \
        _vadd2scale < (n); \
        _vadd2scale++) { \
                (o)[_vadd2scale] = ((a)[_vadd2scale] + (b)[_vadd2scale]) * (s); \
        } \
}

Definition at line 994 of file vmath.h.

#define VSUB2SCALE ( o,
a,
b,
 ) 
Value:
{ \
                        (o)[X] = ((a)[X] - (b)[X]) * (s); \
                        (o)[Y] = ((a)[Y] - (b)[Y]) * (s); \
                        (o)[Z] = ((a)[Z] - (b)[Z]) * (s); \
}

Find the difference between two points, and scale result. Often used to compute bounding sphere radius given rpp points.

Definition at line 1007 of file vmath.h.

#define VSUB2SCALEN ( o,
a,
b,
n   ) 
Value:
{ \
        register int _vsub2scale; \
        for (_vsub2scale = 0; \
        _vsub2scale < (n); \
        _vsub2scale++) { \
                (o)[_vsub2scale] = ((a)[_vsub2scale] - (b)[_vsub2scale]) * (s); \
        } \
}

Definition at line 1013 of file vmath.h.

#define VCOMB3 ( o,
a,
b,
c,
d,
e,
 ) 
Value:
{ \
        (o)[X] = (a) * (b)[X] + (c) * (d)[X] + (e) * (f)[X]; \
        (o)[Y] = (a) * (b)[Y] + (c) * (d)[Y] + (e) * (f)[Y]; \
        (o)[Z] = (a) * (b)[Z] + (c) * (d)[Z] + (e) * (f)[Z]; \
}

Combine together several vectors, scaled by a scalar.

Definition at line 1024 of file vmath.h.

#define VCOMB3N ( o,
a,
b,
c,
d,
e,
f,
n   ) 
Value:
{ \
        register int _vcomb3; \
        for (_vcomb3 = 0; \
        _vcomb3 < (n); \
        _vcomb3++) { \
                (o)[_vcomb3] = (a) * (b)[_vcomb3] + (c) * (d)[_vcomb3] + (e) * (f)[_vcomb3]; \
        } \
}

Definition at line 1030 of file vmath.h.

#define VCOMB2 ( o,
a,
b,
c,
 ) 
Value:
{ \
        (o)[X] = (a) * (b)[X] + (c) * (d)[X]; \
        (o)[Y] = (a) * (b)[Y] + (c) * (d)[Y]; \
        (o)[Z] = (a) * (b)[Z] + (c) * (d)[Z]; \
}

Definition at line 1039 of file vmath.h.

#define VCOMB2N ( o,
a,
b,
c,
d,
n   ) 
Value:
{ \
        register int _vcomb2; \
        for (_vcomb2 = 0; \
        _vcomb2 < (n); \
        _vcomb2++) { \
                (o)[_vcomb2] = (a) * (b)[_vcomb2] + (c) * (d)[_vcomb2]; \
        } \
}

Definition at line 1045 of file vmath.h.

#define VJOIN4 ( a,
b,
c,
d,
e,
f,
g,
h,
i,
 ) 
Value:
{ \
        (a)[X] = (b)[X] + (c)*(d)[X] + (e)*(f)[X] + (g)*(h)[X] + (i)*(j)[X]; \
        (a)[Y] = (b)[Y] + (c)*(d)[Y] + (e)*(f)[Y] + (g)*(h)[Y] + (i)*(j)[Y]; \
        (a)[Z] = (b)[Z] + (c)*(d)[Z] + (e)*(f)[Z] + (g)*(h)[Z] + (i)*(j)[Z]; \
}

Definition at line 1054 of file vmath.h.

#define VJOIN3 ( a,
b,
c,
d,
e,
f,
g,
 ) 
Value:
{ \
        (a)[X] = (b)[X] + (c)*(d)[X] + (e)*(f)[X] + (g)*(h)[X]; \
        (a)[Y] = (b)[Y] + (c)*(d)[Y] + (e)*(f)[Y] + (g)*(h)[Y]; \
        (a)[Z] = (b)[Z] + (c)*(d)[Z] + (e)*(f)[Z] + (g)*(h)[Z]; \
}

Definition at line 1060 of file vmath.h.

#define VJOIN2 ( a,
b,
c,
d,
e,
 ) 
Value:
{ \
        (a)[X] = (b)[X] + (c) * (d)[X] + (e) * (f)[X]; \
        (a)[Y] = (b)[Y] + (c) * (d)[Y] + (e) * (f)[Y]; \
        (a)[Z] = (b)[Z] + (c) * (d)[Z] + (e) * (f)[Z]; \
}

Compose 3D vector at `a' of: Vector at `b' plus scalar `c' times vector at `d' plus scalar `e' times vector at `f'.

Definition at line 1073 of file vmath.h.

#define V2JOIN2 ( a,
b,
c,
d,
e,
 ) 
Value:
{ \
        (a)[X] = (b)[X] + (c) * (d)[X] + (e) * (f)[X]; \
        (a)[Y] = (b)[Y] + (c) * (d)[Y] + (e) * (f)[Y]; \
}

Compose 2D vector at `a' of: Vector at `b' plus scalar `c' times vector at `d' plus scalar `e' times vector at `f'.

Definition at line 1085 of file vmath.h.

#define HJOIN2 ( a,
b,
c,
d,
e,
 ) 
Value:
{ \
        (a)[X] = (b)[X] + (c) * (d)[X] + (e) * (f)[X]; \
        (a)[Y] = (b)[Y] + (c) * (d)[Y] + (e) * (f)[Y]; \
        (a)[Z] = (b)[Z] + (c) * (d)[Z] + (e) * (f)[Z]; \
        (a)[W] = (b)[W] + (c) * (d)[W] + (e) * (f)[W]; \
}

Compose 4D vector at `a' of: Vector at `b' plus scalar `c' times vector at `d' plus scalar `e' times vector at `f'.

Definition at line 1096 of file vmath.h.

#define VJOIN2N ( a,
b,
c,
d,
e,
f,
n   ) 
Value:
{ \
        register int _vjoin2; \
        for (_vjoin2 = 0; \
        _vjoin2 < (n); \
        _vjoin2++) { \
                (a)[_vjoin2] = (b)[_vjoin2] + (c) * (d)[_vjoin2] + (e) * (f)[_vjoin2]; \
        } \
}

Definition at line 1103 of file vmath.h.

#define VJOIN1 ( a,
b,
c,
 ) 
Value:
{ \
        (a)[X] = (b)[X] + (c) * (d)[X]; \
        (a)[Y] = (b)[Y] + (c) * (d)[Y]; \
        (a)[Z] = (b)[Z] + (c) * (d)[Z]; \
}

Definition at line 1113 of file vmath.h.

Referenced by bn_2line3_colinear(), bn_dist_line3_line3(), bn_dist_pt3_line3(), bn_dist_pt3_lseg3(), bn_distsq_line3_line3(), bn_does_ray_isect_tri(), bn_isect_lseg_rpp(), bn_math_cmd(), pdv_3ray(), and tp_3axis().

#define V2JOIN1 ( a,
b,
c,
 ) 
Value:
{ \
        (a)[X] = (b)[X] + (c) * (d)[X]; \
        (a)[Y] = (b)[Y] + (c) * (d)[Y]; \
}

Definition at line 1119 of file vmath.h.

Referenced by bn_dist_pt2_lseg2().

#define HJOIN1 ( a,
b,
c,
 ) 
Value:
{ \
        (a)[X] = (b)[X] + (c) * (d)[X]; \
        (a)[Y] = (b)[Y] + (c) * (d)[Y]; \
        (a)[Z] = (b)[Z] + (c) * (d)[Z]; \
        (a)[W] = (b)[W] + (c) * (d)[W]; \
}

Definition at line 1124 of file vmath.h.

#define VJOIN1N ( a,
b,
c,
d,
n   ) 
Value:
{ \
        register int _vjoin1; \
        for (_vjoin1 = 0; \
        _vjoin1 < (n); \
        _vjoin1++) { \
                (a)[_vjoin1] = (b)[_vjoin1] + (c) * (d)[_vjoin1]; \
        } \
}

Definition at line 1131 of file vmath.h.

#define VBLEND2 ( a,
b,
c,
d,
 ) 
Value:
{ \
        (a)[X] = (b) * (c)[X] + (d) * (e)[X]; \
        (a)[Y] = (b) * (c)[Y] + (d) * (e)[Y]; \
        (a)[Z] = (b) * (c)[Z] + (d) * (e)[Z]; \
}

Blend into vector `a' scalar `b' times vector at `c' plus scalar `d' times vector at `e'.

Definition at line 1146 of file vmath.h.

Referenced by bn_distsq_line3_line3(), bn_math_cmd(), and quat_slerp().

#define VBLEND2N ( a,
b,
c,
d,
e,
n   ) 
Value:
{ \
        register int _vblend2; \
        for (_vblend2 = 0; \
        _vblend2 < (n); \
        _vblend2++) { \
                (a)[_vblend2] = (b) * (c)[_vblend2] + (d) * (e)[_vblend2]; \
        } \
}

Definition at line 1152 of file vmath.h.

#define VPROJECT ( a,
b,
c,
 ) 
Value:
{ \
    VSCALE(c, b, VDOT(a, b) / VDOT(b, b)); \
    VSUB2(d, a, c); \
}

Project vector `a' onto `b' vector `c' is the component of `a' parallel to `b' " `d' " " " " " orthogonal " ".

Definition at line 1167 of file vmath.h.

#define MAGSQ (  )     ((a)[X]*(a)[X] + (a)[Y]*(a)[Y] + (a)[Z]*(a)[Z])
#define MAG2SQ (  )     ((a)[X]*(a)[X] + (a)[Y]*(a)[Y])

Definition at line 1174 of file vmath.h.

#define MAGNITUDE (  )     sqrt(MAGSQ(a))
#define VCROSS ( a,
b,
c   ) 
Value:
{ \
        (a)[X] = (b)[Y] * (c)[Z] - (b)[Z] * (c)[Y]; \
        (a)[Y] = (b)[Z] * (c)[X] - (b)[X] * (c)[Z]; \
        (a)[Z] = (b)[X] * (c)[Y] - (b)[Y] * (c)[X]; \
}

Store cross product of vectors at `b' and `c' in vector at `a'. Note that the "right hand rule" applies: If closing your right hand goes from `b' to `c', then your thumb points in the direction of the cross product.

If the angle from `b' to `c' goes clockwise, then the result vector points "into" the plane (inward normal). Example: b=(0, 1, 0), c=(1, 0, 0), then bXc=(0, 0, -1).

If the angle from `b' to `c' goes counter-clockwise, then the result vector points "out" of the plane. This outward pointing normal is the BRL-CAD convention.

Definition at line 1193 of file vmath.h.

Referenced by bn_aet_vec(), bn_does_ray_isect_tri(), bn_isect_2planes(), bn_mat_fromto(), bn_mk_plane_3pts(), bn_mkpoint_3planes(), bn_vec_perp(), and tp_3vector().

#define VDOT ( a,
 )     ((a)[X]*(b)[X] + (a)[Y]*(b)[Y] + (a)[Z]*(b)[Z])
#define V2DOT ( a,
 )     ((a)[X]*(b)[X] + (a)[Y]*(b)[Y])

Definition at line 1202 of file vmath.h.

#define HDOT ( a,
 )     ((a)[X]*(b)[X] + (a)[Y]*(b)[Y] + (a)[Z]*(b)[Z] + (a)[W]*(b)[W])

Definition at line 1204 of file vmath.h.

#define VSUB2DOT ( _pt2,
_pt,
_vec   ) 
Value:
(\
        ((_pt2)[X] - (_pt)[X]) * (_vec)[X] + \
        ((_pt2)[Y] - (_pt)[Y]) * (_vec)[Y] + \
        ((_pt2)[Z] - (_pt)[Z]) * (_vec)[Z])

Subtract two points to make a vector, dot with another vector.

Definition at line 1211 of file vmath.h.

#define V2ARGS (  )     (a)[X], (a)[Y]

Turn a vector into comma-separated list of elements, for subroutine args.

Definition at line 1220 of file vmath.h.

Referenced by bn_dist_pt2_along_line2(), bn_isect_line2_line2(), bn_isect_line2_lseg2(), and bn_isect_lseg2_lseg2().

#define V3ARGS (  )     (a)[X], (a)[Y], (a)[Z]
#define V4ARGS (  )     (a)[X], (a)[Y], (a)[Z], (a)[W]

Definition at line 1222 of file vmath.h.

Referenced by bn_isect_planes().

#define INTCLAMP ( _a   )     (NEAR_EQUAL((_a), rint(_a), VUNITIZE_TOL) ? (double)(long)rint(_a) : (_a))

if a value is within computation tolerance of an integer, clamp the value to that integer.

NOTE: should use VDIVIDE_TOL here, but cannot yet until floats are replaced universally with fastf_t's since their epsilon is considerably less than that of a double.

Definition at line 1232 of file vmath.h.

Referenced by bn_encode_mat(), and bn_math_cmd().

#define V2INTCLAMPARGS (  )     INTCLAMP((a)[X]), INTCLAMP((a)[Y])

integer clamped versions of the previous arg macros.

Definition at line 1235 of file vmath.h.

Referenced by bn_math_cmd().

#define V3INTCLAMPARGS (  )     INTCLAMP((a)[X]), INTCLAMP((a)[Y]), INTCLAMP((a)[Z])

integer clamped versions of the previous arg macros.

Definition at line 1237 of file vmath.h.

Referenced by bn_encode_vect(), and bn_math_cmd().

#define V4INTCLAMPARGS (  )     INTCLAMP((a)[X]), INTCLAMP((a)[Y]), INTCLAMP((a)[Z]), INTCLAMP((a)[W])

integer clamped versions of the previous arg macros.

Definition at line 1239 of file vmath.h.

Referenced by bn_encode_hvect(), and bn_encode_quat().

#define V2PRINT ( a,
 )     (void)fprintf(stderr, "%s (%g, %g)\n", a, V2ARGS(b));

Print vector name and components on stderr.

Definition at line 1242 of file vmath.h.

Referenced by bn_isect_line2_lseg2(), and bn_isect_pt2_lseg2().

#define VPRINT ( a,
 )     (void)fprintf(stderr, "%s (%g, %g, %g)\n", a, V3ARGS(b));

Definition at line 1244 of file vmath.h.

Referenced by bn_mat_lookat().

#define HPRINT ( a,
 )     (void)fprintf(stderr, "%s (%g, %g, %g, %g)\n", a, V4ARGS(b));

Definition at line 1246 of file vmath.h.

#define V2INTCLAMPPRINT ( a,
 )     (void)fprintf(stderr, "%s (%g, %g)\n", a, V2INTCLAMPARGS(b));

Included below are integer clamped versions of the previous print macros.

Definition at line 1254 of file vmath.h.

#define VINTCLAMPPRINT ( a,
 )     (void)fprintf(stderr, "%s (%g, %g, %g)\n", a, V3INTCLAMPARGS(b));

Definition at line 1256 of file vmath.h.

#define HINTCLAMPPRINT ( a,
 )     (void)fprintf(stderr, "%s (%g, %g, %g, %g)\n", a, V4INTCLAMPARGS(b));

Definition at line 1258 of file vmath.h.

#define VELMUL ( a,
b,
c   ) 
Value:
{ \
        (a)[X] = (b)[X] * (c)[X]; \
        (a)[Y] = (b)[Y] * (c)[Y]; \
        (a)[Z] = (b)[Z] * (c)[Z]; \
}

Vector element multiplication. Really: diagonal matrix X vect.

Definition at line 1271 of file vmath.h.

#define VELMUL3 ( a,
b,
c,
 ) 
Value:
{ \
        (a)[X] = (b)[X] * (c)[X] * (d)[X]; \
        (a)[Y] = (b)[Y] * (c)[Y] * (d)[Y]; \
        (a)[Z] = (b)[Z] * (c)[Z] * (d)[Z]; \
}

Definition at line 1277 of file vmath.h.

#define VELDIV ( a,
b,
c   ) 
Value:
{ \
        (a)[0] = (b)[0] / (c)[0]; \
        (a)[1] = (b)[1] / (c)[1]; \
        (a)[2] = (b)[2] / (c)[2]; \
}

Similar to VELMUL.

Definition at line 1284 of file vmath.h.

#define VINVDIR ( _inv,
_dir   ) 
Value:
{ \
        if ((_dir)[X] < -SQRT_SMALL_FASTF || (_dir)[X] > SQRT_SMALL_FASTF) { \
                (_inv)[X]=1.0/(_dir)[X]; \
        } else { \
                (_dir)[X] = 0.0; \
                (_inv)[X] = INFINITY; \
        } \
        if ((_dir)[Y] < -SQRT_SMALL_FASTF || (_dir)[Y] > SQRT_SMALL_FASTF) { \
                (_inv)[Y]=1.0/(_dir)[Y]; \
        } else { \
                (_dir)[Y] = 0.0; \
                (_inv)[Y] = INFINITY; \
        } \
        if ((_dir)[Z] < -SQRT_SMALL_FASTF || (_dir)[Z] > SQRT_SMALL_FASTF) { \
                (_inv)[Z]=1.0/(_dir)[Z]; \
        } else { \
                (_dir)[Z] = 0.0; \
                (_inv)[Z] = INFINITY; \
        } \
    }

Given a direction vector, compute the inverses of each element. When division by zero would have occured, mark inverse as INFINITY.

Definition at line 1294 of file vmath.h.

#define MAT3X3VEC ( o,
mat,
vec   ) 
Value:
{ \
        (o)[X] = (mat)[X]*(vec)[X]+(mat)[Y]*(vec)[Y] + (mat)[ 2]*(vec)[Z]; \
        (o)[Y] = (mat)[4]*(vec)[X]+(mat)[5]*(vec)[Y] + (mat)[ 6]*(vec)[Z]; \
        (o)[Z] = (mat)[8]*(vec)[X]+(mat)[9]*(vec)[Y] + (mat)[10]*(vec)[Z]; \
}

Apply the 3x3 part of a mat_t to a 3-tuple. This rotates a vector without scaling it (changing its length).

Definition at line 1319 of file vmath.h.

#define VEC3X3MAT ( o,
i,
 ) 
Value:
{ \
        (o)[X] = (i)[X]*(m)[X] + (i)[Y]*(m)[4] + (i)[Z]*(m)[8]; \
        (o)[Y] = (i)[X]*(m)[1] + (i)[Y]*(m)[5] + (i)[Z]*(m)[9]; \
        (o)[Z] = (i)[X]*(m)[2] + (i)[Y]*(m)[6] + (i)[Z]*(m)[10]; \
}

Multiply a 3-tuple by the 3x3 part of a mat_t.

Definition at line 1326 of file vmath.h.

#define MAT3X2VEC ( o,
mat,
vec   ) 
Value:
{ \
        (o)[X] = (mat)[0]*(vec)[X] + (mat)[Y]*(vec)[Y]; \
        (o)[Y] = (mat)[4]*(vec)[X] + (mat)[5]*(vec)[Y]; \
        (o)[Z] = (mat)[8]*(vec)[X] + (mat)[9]*(vec)[Y]; \
}

Apply the 3x3 part of a mat_t to a 2-tuple (Z part=0).

Definition at line 1333 of file vmath.h.

#define VEC2X3MAT ( o,
i,
 ) 
Value:
{ \
        (o)[X] = (i)[X]*(m)[0] + (i)[Y]*(m)[4]; \
        (o)[Y] = (i)[X]*(m)[1] + (i)[Y]*(m)[5]; \
        (o)[Z] = (i)[X]*(m)[2] + (i)[Y]*(m)[6]; \
}

Multiply a 2-tuple (Z=0) by the 3x3 part of a mat_t.

Definition at line 1340 of file vmath.h.

#define MAT4X3PNT ( o,
m,
 ) 
Value:
{ \
        register double _f; \
        _f = 1.0/((m)[12]*(i)[X] + (m)[13]*(i)[Y] + (m)[14]*(i)[Z] + (m)[15]); \
        (o)[X]=((m)[0]*(i)[X] + (m)[1]*(i)[Y] + (m)[ 2]*(i)[Z] + (m)[3]) * _f; \
        (o)[Y]=((m)[4]*(i)[X] + (m)[5]*(i)[Y] + (m)[ 6]*(i)[Z] + (m)[7]) * _f; \
        (o)[Z]=((m)[8]*(i)[X] + (m)[9]*(i)[Y] + (m)[10]*(i)[Z] + (m)[11])* _f; \
}

Apply a 4x4 matrix to a 3-tuple which is an absolute Point in space. Output and input points should be separate arrays.

Definition at line 1350 of file vmath.h.

Referenced by bn_isect_planes(), bn_rotate_plane(), bn_vlist_3string(), tp_3axis(), and tp_3symbol().

#define PNT3X4MAT ( o,
i,
 ) 
Value:
{ \
        register double _f; \
        _f = 1.0/((i)[X]*(m)[3] + (i)[Y]*(m)[7] + (i)[Z]*(m)[11] + (m)[15]); \
        (o)[X]=((i)[X]*(m)[0] + (i)[Y]*(m)[4] + (i)[Z]*(m)[8] + (m)[12]) * _f; \
        (o)[Y]=((i)[X]*(m)[1] + (i)[Y]*(m)[5] + (i)[Z]*(m)[9] + (m)[13]) * _f; \
        (o)[Z]=((i)[X]*(m)[2] + (i)[Y]*(m)[6] + (i)[Z]*(m)[10] + (m)[14])* _f; \
}

Multiply an Absolute 3-Point by a full 4x4 matrix. Output and input points should be separate arrays.

Definition at line 1362 of file vmath.h.

#define MAT4X4PNT ( o,
m,
 ) 
Value:
{ \
        (o)[X]=(m)[ 0]*(i)[X] + (m)[ 1]*(i)[Y] + (m)[ 2]*(i)[Z] + (m)[ 3]*(i)[H]; \
        (o)[Y]=(m)[ 4]*(i)[X] + (m)[ 5]*(i)[Y] + (m)[ 6]*(i)[Z] + (m)[ 7]*(i)[H]; \
        (o)[Z]=(m)[ 8]*(i)[X] + (m)[ 9]*(i)[Y] + (m)[10]*(i)[Z] + (m)[11]*(i)[H]; \
        (o)[H]=(m)[12]*(i)[X] + (m)[13]*(i)[Y] + (m)[14]*(i)[Z] + (m)[15]*(i)[H]; \
}

Multiply an Absolute hvect_t 4-Point by a full 4x4 matrix. Output and input points should be separate arrays.

Definition at line 1374 of file vmath.h.

#define MAT4X3VEC ( o,
m,
 ) 
Value:
{ \
        register double _f; \
        _f = 1.0/((m)[15]); \
        (o)[X] = ((m)[0]*(i)[X] + (m)[1]*(i)[Y] + (m)[ 2]*(i)[Z]) * _f; \
        (o)[Y] = ((m)[4]*(i)[X] + (m)[5]*(i)[Y] + (m)[ 6]*(i)[Z]) * _f; \
        (o)[Z] = ((m)[8]*(i)[X] + (m)[9]*(i)[Y] + (m)[10]*(i)[Z]) * _f; \
}

Apply a 4x4 matrix to a 3-tuple which is a relative Vector in space. This macro can scale the length of the vector if [15] != 1.0. Output and input vectors should be separate arrays.

Definition at line 1386 of file vmath.h.

Referenced by bn_mat_fromto(), bn_mat_lookat(), bn_rotate_plane(), and tp_3axis().

#define MAT4XSCALOR ( o,
m,
 ) 
Value:
{ \
        (o) = (i) / (m)[15]; \
}

Definition at line 1394 of file vmath.h.

#define VEC3X4MAT ( o,
i,
 ) 
Value:
{ \
        register double _f; \
        _f = 1.0/((m)[15]); \
        (o)[X] = ((i)[X]*(m)[0] + (i)[Y]*(m)[4] + (i)[Z]*(m)[8]) * _f; \
        (o)[Y] = ((i)[X]*(m)[1] + (i)[Y]*(m)[5] + (i)[Z]*(m)[9]) * _f; \
        (o)[Z] = ((i)[X]*(m)[2] + (i)[Y]*(m)[6] + (i)[Z]*(m)[10]) * _f; \
}

Multiply a Relative 3-Vector by most of a 4x4 matrix. Output and input vectors should be separate arrays.

Definition at line 1402 of file vmath.h.

#define VEC2X4MAT ( o,
i,
 ) 
Value:
{ \
        register double _f; \
        _f = 1.0/((m)[15]); \
        (o)[X] = ((i)[X]*(m)[0] + (i)[Y]*(m)[4]) * _f; \
        (o)[Y] = ((i)[X]*(m)[1] + (i)[Y]*(m)[5]) * _f; \
        (o)[Z] = ((i)[X]*(m)[2] + (i)[Y]*(m)[6]) * _f; \
}

Multiply a Relative 2-Vector by most of a 4x4 matrix.

Definition at line 1411 of file vmath.h.

#define BN_VEC_NON_UNIT_LEN ( _vec   )     (fabs(MAGSQ(_vec)) < 0.0001 || fabs(fabs(MAGSQ(_vec))-1) > 0.0001)

Test a vector for non-unit length.

Definition at line 1420 of file vmath.h.

#define V_MIN ( r,
 )     if ((r) > (s)) r = (s)

Included below are macros to update min and max X, Y, Z values to contain a point.

Definition at line 1428 of file vmath.h.

#define V_MAX ( r,
 )     if ((r) < (s)) r = (s)

Definition at line 1430 of file vmath.h.

#define VMIN ( r,
 ) 
Value:
{ \
        V_MIN((r)[X], (s)[X]); V_MIN((r)[Y], (s)[Y]); V_MIN((r)[Z], (s)[Z]); \
}

Definition at line 1432 of file vmath.h.

#define VMAX ( r,
 ) 
Value:
{ \
        V_MAX((r)[X], (s)[X]); V_MAX((r)[Y], (s)[Y]); V_MAX((r)[Z], (s)[Z]); \
}

Definition at line 1436 of file vmath.h.

#define VMINMAX ( min,
max,
pt   ) 
Value:
{ \
        VMIN((min), (pt)); VMAX((max), (pt)); \
}

Definition at line 1440 of file vmath.h.

#define HDIVIDE ( a,
 ) 
Value:
{ \
        (a)[X] = (b)[X] / (b)[H]; \
        (a)[Y] = (b)[Y] / (b)[H]; \
        (a)[Z] = (b)[Z] / (b)[H]; \
}

Divide out homogeneous parameter from hvect_t, creating vect_t.

Definition at line 1448 of file vmath.h.

#define VADD2_2D ( a,
b,
c   )     V2ADD2(a, b, c)

Some 2-D versions of the 3-D macros given above.

A better naming convention is V2MOVE() rather than VMOVE_2D().

DEPRECATED: These xxx_2D names are slated to go away, use the others.

THESE ARE ALL DEPRECATED.

Definition at line 1464 of file vmath.h.

Referenced by bn_isect_line2_lseg2().

#define VSUB2_2D ( a,
b,
c   )     V2SUB2(a, b, c)
#define MAGSQ_2D (  )     MAG2SQ(a)
#define VDOT_2D ( a,
 )     V2DOT(a, b)
#define VMOVE_2D ( a,
 )     V2MOVE(a, b)

Definition at line 1468 of file vmath.h.

Referenced by bn_isect_pt2_lseg2().

#define VSCALE_2D ( a,
b,
c   )     V2SCALE(a, b, c)

Definition at line 1469 of file vmath.h.

Referenced by bn_isect_pt2_lseg2().

#define VJOIN1_2D ( a,
b,
c,
 )     V2JOIN1(a, b, c, d)

Definition at line 1470 of file vmath.h.

Referenced by bn_isect_line2_lseg2().

#define QUAT_FROM_ROT ( q,
r,
x,
y,
z   ) 
Value:
{ \
        register fastf_t _rot = (r) * 0.5; \
        QSET(q, x, y, z, cos(_rot)); \
        VUNITIZE(q); \
        _rot = sin(_rot); /* _rot is really just a temp variable now */ \
        VSCALE(q, q, _rot); \
}

Quaternion math definitions.

Note that the [W] component will be put in the last (i.e., third) place rather than the first [X] (i.e., [0]) place, so that the X, Y, and Z elements will be compatible with vectors. Only QUAT_FROM_VROT macros depend on component locations, however. Create Quaternion from Vector and Rotation about vector. To produce a quaternion representing a rotation by PI radians about X-axis:

VSET(axis, 1, 0, 0); QUAT_FROM_VROT(quat, M_PI, axis); or QUAT_FROM_ROT(quat, M_PI, 1.0, 0.0, 0.0, 0.0);

Alternatively, in degrees: QUAT_FROM_ROT_DEG(quat, 180.0, 1.0, 0.0, 0.0, 0.0);

Definition at line 1496 of file vmath.h.

#define QUAT_FROM_VROT ( q,
r,
 ) 
Value:
{ \
        register fastf_t _rot = (r) * 0.5; \
        VMOVE(q, v); \
        VUNITIZE(q); \
        (q)[W] = cos(_rot); \
        _rot = sin(_rot); /* _rot is really just a temp variable now */ \
        VSCALE(q, q, _rot); \
}

Definition at line 1504 of file vmath.h.

#define QUAT_FROM_VROT_DEG ( q,
r,
 )     QUAT_FROM_VROT(q, ((r)*(M_PI/180.0)), v)

Definition at line 1513 of file vmath.h.

#define QUAT_FROM_ROT_DEG ( q,
r,
x,
y,
z   )     QUAT_FROM_ROT(q, ((r)*(M_PI/180.0)), x, y, z)

Definition at line 1516 of file vmath.h.

#define QSET ( a,
b,
c,
d,
 ) 
Value:
{ \
        (a)[X] = (b); \
        (a)[Y] = (c); \
        (a)[Z] = (d); \
        (a)[W] = (e); \
}

Set quaternion at `a' to have coordinates `b', `c', `d', and `e'.

Definition at line 1524 of file vmath.h.

#define QMOVE ( a,
 ) 
Value:
{ \
        (a)[X] = (b)[X]; \
        (a)[Y] = (b)[Y]; \
        (a)[Z] = (b)[Z]; \
        (a)[W] = (b)[W]; \
}

Transfer quaternion at `b' to quaternion at `a'.

Definition at line 1532 of file vmath.h.

Referenced by anim_quat2mat(), quat_make_nearest(), and quat_quat2mat().

#define QADD2 ( a,
b,
c   ) 
Value:
{ \
        (a)[X] = (b)[X] + (c)[X]; \
        (a)[Y] = (b)[Y] + (c)[Y]; \
        (a)[Z] = (b)[Z] + (c)[Z]; \
        (a)[W] = (b)[W] + (c)[W]; \
}

Add quaternions at `b' and `c', store result at `a'.

Definition at line 1540 of file vmath.h.

Referenced by quat_bisect().

#define QSUB2 ( a,
b,
c   ) 
Value:
{ \
        (a)[X] = (b)[X] - (c)[X]; \
        (a)[Y] = (b)[Y] - (c)[Y]; \
        (a)[Z] = (b)[Z] - (c)[Z]; \
        (a)[W] = (b)[W] - (c)[W]; \
}

Subtract quaternion at `c' from quaternion at `b', store result at `a'.

Definition at line 1551 of file vmath.h.

Referenced by quat_distance(), and quat_double().

#define QSCALE ( a,
b,
c   ) 
Value:
{ \
        (a)[X] = (b)[X] * (c); \
        (a)[Y] = (b)[Y] * (c); \
        (a)[Z] = (b)[Z] * (c); \
        (a)[W] = (b)[W] * (c); \
}

Scale quaternion at `b' by scalar `c', store result at `a'.

Definition at line 1562 of file vmath.h.

Referenced by quat_double(), and quat_make_nearest().

#define QUNITIZE (  ) 
Value:
{ \
        register double _f; \
        _f = QMAGNITUDE(a); \
        if (_f < VDIVIDE_TOL) _f = 0.0; else _f = 1.0/_f; \
        (a)[X] *= _f; (a)[Y] *= _f; (a)[Z] *= _f; (a)[W] *= _f; \
}

Normalize quaternion 'a' to be a unit quaternion.

Definition at line 1570 of file vmath.h.

Referenced by anim_quat2mat(), quat_bisect(), quat_double(), and quat_quat2mat().

#define QMAGSQ (  ) 
Value:
((a)[X]*(a)[X] + (a)[Y]*(a)[Y] \
        + (a)[Z]*(a)[Z] + (a)[W]*(a)[W])

Return scalar magnitude squared of quaternion at `a'.

Definition at line 1578 of file vmath.h.

Referenced by anim_mat2quat().

#define QMAGNITUDE (  )     sqrt(QMAGSQ(a))

Return scalar magnitude of quaternion at `a'.

Definition at line 1583 of file vmath.h.

Referenced by quat_distance().

#define QDOT ( a,
 ) 
Value:
((a)[X]*(b)[X] + (a)[Y]*(b)[Y] \
        + (a)[Z]*(b)[Z] + (a)[W]*(b)[W])

Compute dot product of quaternions at `a' and `b'.

Definition at line 1586 of file vmath.h.

Referenced by quat_double(), and quat_slerp().

#define QMUL ( a,
b,
c   ) 
Value:
{ \
        (a)[W] = (b)[W]*(c)[W] - (b)[X]*(c)[X] - (b)[Y]*(c)[Y] - (b)[Z]*(c)[Z]; \
        (a)[X] = (b)[W]*(c)[X] + (b)[X]*(c)[W] + (b)[Y]*(c)[Z] - (b)[Z]*(c)[Y]; \
        (a)[Y] = (b)[W]*(c)[Y] + (b)[Y]*(c)[W] + (b)[Z]*(c)[X] - (b)[X]*(c)[Z]; \
        (a)[Z] = (b)[W]*(c)[Z] + (b)[Z]*(c)[W] + (b)[X]*(c)[Y] - (b)[Y]*(c)[X]; \
}

Compute quaternion product a = b * c.

a[W] = b[W]*c[W] - VDOT(b, c); VCROSS(temp, b, c); VJOIN2(a, temp, b[W], c, c[W], b);

Definition at line 1597 of file vmath.h.

#define QCONJUGATE ( a,
 ) 
Value:
{ \
        (a)[X] = -(b)[X]; \
        (a)[Y] = -(b)[Y]; \
        (a)[Z] = -(b)[Z]; \
        (a)[W] =  (b)[W]; \
}

Conjugate quaternion.

Definition at line 1605 of file vmath.h.

#define QINVERSE ( a,
 ) 
Value:
{ \
        register double _f = QMAGSQ(b); \
        if (_f < VDIVIDE_TOL) _f = 0.0; else _f = 1.0/_f; \
        (a)[X] = -(b)[X] * _f; \
        (a)[Y] = -(b)[Y] * _f; \
        (a)[Z] = -(b)[Z] * _f; \
        (a)[W] =  (b)[W] * _f; \
}

Multiplicative inverse quaternion.

Definition at line 1613 of file vmath.h.

#define QBLEND2 ( a,
b,
c,
d,
 ) 
Value:
{ \
        (a)[X] = (b) * (c)[X] + (d) * (e)[X]; \
        (a)[Y] = (b) * (c)[Y] + (d) * (e)[Y]; \
        (a)[Z] = (b) * (c)[Z] + (d) * (e)[Z]; \
        (a)[W] = (b) * (c)[W] + (d) * (e)[W]; \
}

Blend into quaternion `a'.

scalar `b' times quaternion at `c' plus scalar `d' times quaternion at `e'

Definition at line 1628 of file vmath.h.

Referenced by quat_slerp().

#define V3RPP_DISJOINT ( _l1,
_h1,
_l2,
_h2   ) 
Value:
((_l1)[X] > (_h2)[X] || (_l1)[Y] > (_h2)[Y] || (_l1)[Z] > (_h2)[Z] || \
        (_l2)[X] > (_h1)[X] || (_l2)[Y] > (_h1)[Y] || (_l2)[Z] > (_h1)[Z])

Macros for dealing with 3-D "extents", aka bounding boxes, that are represented as axis-aligned right parallelpipeds (RPPs). This is stored as two points: a min point, and a max point. RPP 1 is defined by lo1, hi1, RPP 2 by lo2, hi2. Compare two bounding boxes and return true if they are disjoint.

Definition at line 1645 of file vmath.h.

#define V3RPP_DISJOINT_TOL ( _l1,
_h1,
_l2,
_h2,
_t   ) 
Value:
(((_l1)[X] > (_h2)[X] + (_t) && \
        (_l1)[Y] > (_h2)[Y] + (_t) && \
        (_l1)[Z] > (_h2)[Z] + (_t)) || \
       ((_l2)[X] > (_h1)[X] + (_t) && \
        (_l2)[Y] > (_h1)[Y] + (_t) && \
        (_l2)[Z] > (_h1)[Z] + (_t)))

Compare two bounding boxes and return true if they are disjoint by at least distance tolerance.

Definition at line 1653 of file vmath.h.

#define V3RPP_OVERLAP ( _l1,
_h1,
_l2,
_h2   ) 
Value:
(! ((_l1)[X] > (_h2)[X] || (_l1)[Y] > (_h2)[Y] || (_l1)[Z] > (_h2)[Z] || \
        (_l2)[X] > (_h1)[X] || (_l2)[Y] > (_h1)[Y] || (_l2)[Z] > (_h1)[Z]))

Compare two bounding boxes and return true If they overlap.

Definition at line 1662 of file vmath.h.

#define V3RPP_OVERLAP_TOL ( _l1,
_h1,
_l2,
_h2,
_t   ) 
Value:
(! ((_l1)[X] > (_h2)[X] + (_t) || \
        (_l1)[Y] > (_h2)[Y] + (_t) || \
        (_l1)[Z] > (_h2)[Z] + (_t) || \
        (_l2)[X] > (_h1)[X] + (_t) || \
        (_l2)[Y] > (_h1)[Y] + (_t) || \
        (_l2)[Z] > (_h1)[Z] + (_t)))

If two extents overlap within distance tolerance, return true.

Definition at line 1670 of file vmath.h.

#define V3PT_IN_RPP ( _pt,
_lo,
_hi   ) 
Value:
(\
        (_pt)[X] >= (_lo)[X] && (_pt)[X] <= (_hi)[X] && \
        (_pt)[Y] >= (_lo)[Y] && (_pt)[Y] <= (_hi)[Y] && \
        (_pt)[Z] >= (_lo)[Z] && (_pt)[Z] <= (_hi)[Z])

Is the point within or on the boundary of the RPP?

FIXME: should not be using >= <=, '=' case is unreliable

Definition at line 1683 of file vmath.h.

#define V3PT_IN_RPP_TOL ( _pt,
_lo,
_hi,
_t   ) 
Value:
(\
        (_pt)[X] >= (_lo)[X]-(_t) && (_pt)[X] <= (_hi)[X]+(_t) && \
        (_pt)[Y] >= (_lo)[Y]-(_t) && (_pt)[Y] <= (_hi)[Y]+(_t) && \
        (_pt)[Z] >= (_lo)[Z]-(_t) && (_pt)[Z] <= (_hi)[Z]+(_t))

Within the distance tolerance, is the point within the RPP?

FIXME: should not be using >= <=, '=' case is unreliable

Definition at line 1693 of file vmath.h.

#define V3PT_OUT_RPP_TOL ( _pt,
_lo,
_hi,
_t   ) 
Value:
(\
        (_pt)[X] < (_lo)[X]-(_t) || (_pt)[X] > (_hi)[X]+(_t) || \
        (_pt)[Y] < (_lo)[Y]-(_t) || (_pt)[Y] > (_hi)[Y]+(_t) || \
        (_pt)[Z] < (_lo)[Z]-(_t) || (_pt)[Z] > (_hi)[Z]+(_t))

Is the point outside the RPP by at least the distance tolerance? This will not return true if the point is on the RPP.

Definition at line 1702 of file vmath.h.

#define V3RPP1_IN_RPP2 ( _lo1,
_hi1,
_lo2,
_hi2   ) 
Value:
(\
        (_lo1)[X] >= (_lo2)[X] && (_hi1)[X] <= (_hi2)[X] && \
        (_lo1)[Y] >= (_lo2)[Y] && (_hi1)[Y] <= (_hi2)[Y] && \
        (_lo1)[Z] >= (_lo2)[Z] && (_hi1)[Z] <= (_hi2)[Z])

Determine if one bounding box is within another. Also returns true if the boxes are the same.

FIXME: should not be using >= <=, '=' case is unreliable

Definition at line 1713 of file vmath.h.

#define V3DIR_FROM_AZEL ( _d,
_a,
_e   ) 
Value:
{ \
        register fastf_t _c_e = cos(_e); \
        (_d)[X] = cos(_a) * _c_e; \
        (_d)[Y] = sin(_a) * _c_e; \
        (_d)[Z] = sin(_e); \
}

Convert an azimuth/elevation to a direction vector.

Definition at line 1719 of file vmath.h.

#define AZEL_FROM_V3DIR ( _a,
_e,
_d   ) 
Value:
{ \
        (_a) = ((NEAR_ZERO((_d)[X], SMALL_FASTF)) && (NEAR_ZERO((_d)[Y], SMALL_FASTF))) ? 0.0 : atan2(-((_d)[Y]), -((_d)[X])) * -RAD2DEG; \
        (_e) = atan2(-((_d)[Z]), sqrt((_d)[X]*(_d)[X] + (_d)[Y]*(_d)[Y])) * -RAD2DEG; \
}

Convert a direction vector to azimuth/elevation (in radians).

Definition at line 1727 of file vmath.h.

#define VINITALL ( _v   )     {(_v), (_v), (_v)}

3D vector macro suitable for declaration statement initialization. this sets all vector elements to the specified value similar to VSETALL() but as an initializer array declaration instead of as a statement.

Definition at line 1740 of file vmath.h.

#define V2INITALL ( _v   )     {(_v), (_v), (_v)}

2D vector macro suitable for declaration statement initialization. this sets all vector elements to the specified value similar to VSETALLN(hvect_t,val,2) but as an initializer array declaration instead of as a statement.

Definition at line 1748 of file vmath.h.

#define HINITALL ( _v   )     {(_v), (_v), (_v), (_v)}

4D homogeneous vector macro suitable for declaration statement initialization. this sets all vector elements to the specified value similar to VSETALLN(hvect_t,val,4) but as an initializer array declaration instead of as a statement.

Definition at line 1756 of file vmath.h.

#define VINIT_ZERO   {0.0, 0.0, 0.0}

3D vector macro suitable for declaration statement initialization. this sets all vector elements to zero similar to calling VSETALL(0.0) but as an initializer array declaration instead of as a statement.

Definition at line 1764 of file vmath.h.

Referenced by Add_vert(), and anim_steer_mat().

#define V2INIT_ZERO   {0.0, 0.0}

2D vector macro suitable for declaration statement initialization. this sets all vector elements to zero similar to calling V2SETALL(0.0) but as an initializer array declaration instead of as a statement.

Definition at line 1772 of file vmath.h.

#define HINIT_ZERO   {0.0, 0.0, 0.0, 0.0}

4D homogenous vector macro suitable for declaration statement initialization. this sets all vector elements to zero similar to calling VSETALLN(hvect_t,0.0,4) but as an initializer array declaration instead of as a statement.

Definition at line 1780 of file vmath.h.

#define MAT_INIT_IDN   {1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}

matrix macro suitable for declaration statement initialization. this sets up an identity matrix similar to calling MAT_IDN but as an initializer array declaration instead of as a statement.

Definition at line 1787 of file vmath.h.

#define MAT_INIT_ZERO   {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}

matrix macro suitable for declaration statement initialization. this sets up a zero matrix similar to calling MAT_ZERO but as an initializer array declaration instead of as a statement.

Definition at line 1794 of file vmath.h.


Typedef Documentation

typedef fastf_t vect2d_t[ELEMENTS_PER_VECT2D]

2-tuple vector

Definition at line 200 of file vmath.h.

typedef fastf_t* vect2dp_t

pointer to a 2-tuple vector

Definition at line 203 of file vmath.h.

typedef fastf_t point2d_t[ELEMENTS_PER_POINT2D]

2-tuple point

Definition at line 206 of file vmath.h.

typedef fastf_t* point2dp_t

pointer to a 2-tuple point

Definition at line 209 of file vmath.h.

typedef fastf_t vect_t[ELEMENTS_PER_VECT]

3-tuple vector

Definition at line 212 of file vmath.h.

typedef fastf_t* vectp_t

pointer to a 3-tuple vector

Definition at line 215 of file vmath.h.

typedef fastf_t point_t[ELEMENTS_PER_POINT]

3-tuple point

Definition at line 218 of file vmath.h.

typedef fastf_t* pointp_t

pointer to a 3-tuple point

Definition at line 221 of file vmath.h.

typedef fastf_t hvect_t[ELEMENTS_PER_HVECT]

4-tuple vector

Definition at line 224 of file vmath.h.

typedef hvect_t quat_t

4-element quaternion

Definition at line 227 of file vmath.h.

typedef fastf_t hpoint_t[ELEMENTS_PER_HPOINT]

4-tuple point

Definition at line 230 of file vmath.h.

typedef fastf_t mat_t[ELEMENTS_PER_MAT]

4x4 matrix

Definition at line 233 of file vmath.h.

typedef fastf_t* matp_t

pointer to a 4x4 matrix

Definition at line 236 of file vmath.h.

Vector component names for homogeneous (4-tuple) vectors

Locations of deltas (MD*) and scaling values (MS*) in a 4x4 Homogenous Transform matrix

typedef fastf_t plane_t[ELEMENTS_PER_PLANE]

Definition of a plane equation.

A plane is defined by a unit-length outward pointing normal vector (N), and the perpendicular (shortest) distance from the origin to the plane (in element N[W]).

The plane consists of all points P=(x, y, z) such that
VDOT(P, N) - N[W] == 0
that is,
N[X]*x + N[Y]*y + N[Z]*z - N[W] == 0

The inside of the halfspace bounded by the plane consists of all points P such that
VDOT(P, N) - N[W] <= 0

A ray with direction D is classified w.r.t. the plane by


VDOT(D, N) < 0 ray enters halfspace defined by plane
VDOT(D, N) == 0 ray is parallel to plane
VDOT(D, N) > 0 ray exits halfspace defined by plane

Definition at line 283 of file vmath.h.


Enumeration Type Documentation

Vector component names for homogeneous (4-tuple) vectors

Enumerator:
X 
Y 
Z 
H 
W 

Definition at line 239 of file vmath.h.

Locations of deltas (MD*) and scaling values (MS*) in a 4x4 Homogenous Transform matrix

Enumerator:
MSX 
MDX 
MSY 
MDY 
MSZ 
MDZ 
MSA 

Definition at line 251 of file vmath.h.


Function Documentation

void quat_mat2quat ( quat_t  quat,
const mat_t  mat 
)

Referenced by bn_math_cmd().

void quat_quat2mat ( mat_t  mat,
const quat_t  quat 
)

Referenced by bn_math_cmd().

double quat_distance ( const quat_t  q1,
const quat_t  q2 
)
void quat_double ( quat_t  qout,
const quat_t  q1,
const quat_t  q2 
)

Referenced by bn_math_cmd().

void quat_bisect ( quat_t  qout,
const quat_t  q1,
const quat_t  q2 
)

Referenced by bn_math_cmd().

void quat_slerp ( quat_t  qout,
const quat_t  q1,
const quat_t  q2,
double  f 
)

Referenced by bn_math_cmd(), and quat_sberp().

void quat_sberp ( quat_t  qout,
const quat_t  q1,
const quat_t  qa,
const quat_t  qb,
const quat_t  q2,
double  f 
)

Referenced by bn_math_cmd().

void quat_make_nearest ( quat_t  q1,
const quat_t  q2 
)

Referenced by bn_math_cmd().

void quat_print ( const char *  title,
const quat_t  quat 
)
void quat_exp ( quat_t  out,
const quat_t  in 
)

Referenced by bn_math_cmd().

void quat_log ( quat_t  out,
const quat_t  in 
)

Referenced by bn_math_cmd().

void quat_mat2quat ( register fastf_t *  quat,
register const fastf_t *  mat 
)

Convert Matrix to Quaternion.

Q U A T _ M A T 2 Q U A T

Definition at line 70 of file qmath.c.

References MMM, W, X, XX, Y, YY, Z, and ZZ.

void quat_quat2mat ( register fastf_t *  mat,
register const fastf_t *  quat 
)

Convert Quaternion to Matrix.

Q U A T _ Q U A T 2 M A T NB: This only works for UNIT quaternions. We may get imaginary results otherwise. We should normalize first (still yields same rotation).

Definition at line 137 of file qmath.c.

References QMOVE, QUNITIZE, W, X, Y, and Z.

double quat_distance ( const fastf_t *  q1,
const fastf_t *  q2 
)

Gives the euclidean distance between two quaternions.

Q U A T _ D I S T A N C E

Definition at line 168 of file qmath.c.

References QMAGNITUDE, and QSUB2.

void quat_double ( fastf_t *  qout,
const fastf_t *  q1,
const fastf_t *  q2 
)

Gives the quaternion point representing twice the rotation from q1 to q2. Needed for patching Bezier curves together. A rather poor name admittedly.

Q U A T _ D O U B L E

Definition at line 185 of file qmath.c.

References QDOT, QSCALE, QSUB2, QUNITIZE, and scale.

void quat_bisect ( fastf_t *  qout,
const fastf_t *  q1,
const fastf_t *  q2 
)

Gives the bisector of quaternions q1 and q2. (Could be done with quat_slerp and factor 0.5) [I believe they must be unit quaternions this to work].

Q U A T _ B I S E C T

Definition at line 204 of file qmath.c.

References QADD2, and QUNITIZE.

void quat_slerp ( fastf_t *  qout,
const fastf_t *  q1,
const fastf_t *  q2,
double  f 
)

Do Spherical Linear Interpolation between two unit quaternions by the given factor.

Q U A T _ S L E R P As f goes from 0 to 1, qout goes from q1 to q2. Code based on code by Ken Shoemake

Definition at line 220 of file qmath.c.

References M_PI, QBLEND2, QDOT, VBLEND2, W, X, Y, and Z.

void quat_sberp ( fastf_t *  qout,
const fastf_t *  q1,
const fastf_t *  qa,
const fastf_t *  qb,
const fastf_t *  q2,
double  f 
)

Spherical Bezier Interpolate between four quaternions by amount f. These are intended to be used as start and stop quaternions along with two control quaternions chosen to match spline segments with first order continuity.

Q U A T _ S B E R P Uses the method of successive bisection.

Definition at line 274 of file qmath.c.

References quat_slerp().

Here is the call graph for this function:

void quat_make_nearest ( fastf_t *  q1,
const fastf_t *  q2 
)

Set the quaternion q1 to the quaternion which yields the smallest rotation from q2 (of the two versions of q1 which produce the same orientation).

Q U A T _ M A K E _ N E A R E S T Note that smallest euclidian distance implies smallest great circle distance as well (since surface is convex).

Definition at line 302 of file qmath.c.

References QMOVE, QSCALE, and quat_distance().

Here is the call graph for this function:

void quat_print ( const char *  title,
const fastf_t *  quat 
)

Q U A T _ P R I N T

Definition at line 322 of file qmath.c.

References RAD2DEG, VMOVE, VUNITIZE, W, X, Y, and Z.

void quat_exp ( fastf_t *  out,
const fastf_t *  in 
)

Exponentiate a quaternion, assuming that the scalar part is 0. Code by Ken Shoemake.

Q U A T _ E X P

Definition at line 346 of file qmath.c.

References MAGNITUDE, scale, theta, VDIVIDE_TOL, VSCALE, and W.

void quat_log ( fastf_t *  out,
const fastf_t *  in 
)

Take the natural logarithm of a unit quaternion. Code by Ken Shoemake.

Q U A T _ L O G

Definition at line 367 of file qmath.c.

References MAGNITUDE, scale, theta, VDIVIDE_TOL, VSCALE, and W.

Generated on Tue Dec 11 13:14:29 2012 for LIBBN by  doxygen 1.6.3