vector/matrix math More...
#include "common.h"
#include <math.h>
#include <float.h>
#include "bu.h"
Go to the source code of this file.
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 } |
vector/matrix math
This header file defines many commonly used 3D vector math macros, and operates on vect_t, point_t, mat_t, and quat_t objects.
Note that while many people in the computer graphics field use post-multiplication with row vectors (ie, vector * matrix * matrix ...) the BRL-CAD system uses the more traditional representation of column vectors (ie, ... matrix * matrix * vector). (The matrices in these two representations are the transposes of each other). Therefore, when transforming a vector by a matrix, pre-multiplication is used, ie:
view_vec = model2view_mat * model_vec
Furthermore, additional transformations are multiplied on the left, ie:
vec' = T1 * vec vec'' = T2 * T1 * vec = T2 * vec'
The most notable implication of this is the location of the "delta" (translation) values in the matrix, ie:
Note -
vect_t objects are 3-tuples
hvect_t objects are 4-tuples
Most of these macros require that the result be in separate storage, distinct from the input parameters, except where noted.
When writing macros like this, it is very important that any variables which are declared within code blocks inside a macro start with an underscore. This (hopefully) minimizes any name conflicts with user-provided parameters. For example:
{ register double _f; stuff; }
Definition in file vmath.h.