BRL-CAD
Matrix/Vector/Quaternion Math
Collaboration diagram for Matrix/Vector/Quaternion Math:

Files

file  mat.c
 
file  qmath.c
 Quaternion math routines.
 

Macros

#define bn_mat_zero(_m)
 
#define bn_mat_idn(_m)
 
#define bn_mat_copy(_d, _s)
 

Functions

void bn_mat_print (const char *title, const mat_t m)
 
void bn_mat_print_guts (const char *title, const mat_t m, char *buf, int buflen)
 
void bn_mat_print_vls (const char *title, const mat_t m, struct bu_vls *vls)
 
double bn_atan2 (double x, double y)
 
void bn_mat_mul (mat_t o, const mat_t a, const mat_t b)
 
void bn_mat_mul2 (const mat_t i, mat_t o)
 
void bn_mat_mul3 (mat_t o, const mat_t a, const mat_t b, const mat_t c)
 
void bn_mat_mul4 (mat_t o, const mat_t a, const mat_t b, const mat_t c, const mat_t d)
 
void bn_matXvec (hvect_t ov, const mat_t im, const hvect_t iv)
 
void bn_mat_inv (mat_t output, const mat_t input)
 
int bn_mat_inverse (mat_t output, const mat_t input)
 
void bn_vtoh_move (vect_t h, const vect_t v)
 
void bn_htov_move (vect_t v, const vect_t h)
 
void bn_mat_trn (mat_t om, const mat_t im)
 
void bn_mat_ae (mat_t m, double azimuth, double elev)
 
void bn_ae_vec (fastf_t *azp, fastf_t *elp, const vect_t v)
 
void bn_aet_vec (fastf_t *az, fastf_t *el, fastf_t *twist, vect_t vec_ae, vect_t vec_twist, fastf_t accuracy)
 
void bn_vec_ae (vect_t vec, fastf_t az, fastf_t el)
 
void bn_vec_aed (vect_t vec, fastf_t az, fastf_t el, fastf_t dist)
 
void bn_mat_angles (mat_t mat, double alpha, double beta, double ggamma)
 
void bn_mat_angles_rad (mat_t mat, double alpha, double beta, double ggamma)
 
void bn_eigen2x2 (fastf_t *val1, fastf_t *val2, vect_t vec1, vect_t vec2, fastf_t a, fastf_t b, fastf_t c)
 
void bn_vec_perp (vect_t new_vec, const vect_t old_vec)
 
void bn_mat_fromto (mat_t m, const fastf_t *from, const fastf_t *to, const struct bn_tol *tol)
 
void bn_mat_xrot (mat_t m, double sinx, double cosx)
 
void bn_mat_yrot (mat_t m, double siny, double cosy)
 
void bn_mat_zrot (mat_t m, double sinz, double cosz)
 
void bn_mat_lookat (mat_t rot, const vect_t dir, int yflip)
 
void bn_vec_ortho (vect_t out, const vect_t in)
 
int bn_mat_scale_about_pt (mat_t mat, const point_t pt, const double scale)
 
void bn_mat_xform_about_pt (mat_t mat, const mat_t xform, const point_t pt)
 
int bn_mat_is_equal (const mat_t a, const mat_t b, const struct bn_tol *tol)
 
int bn_mat_is_identity (const mat_t m)
 
void bn_mat_arb_rot (mat_t m, const point_t pt, const vect_t dir, const fastf_t ang)
 
matp_t bn_mat_dup (const mat_t in)
 
int bn_mat_ck (const char *title, const mat_t m)
 
fastf_t bn_mat_det3 (const mat_t m)
 
fastf_t bn_mat_determinant (const mat_t m)
 
int bn_mat_is_non_unif (const mat_t m)
 
void bn_wrt_point_direc (mat_t out, const mat_t change, const mat_t in, const point_t point, const vect_t direc, const struct bn_tol *tol)
 
void persp_mat (mat_t m, fastf_t fovy, fastf_t aspect, fastf_t near1, fastf_t far1, fastf_t backoff)
 
void mike_persp_mat (fastf_t *pmat, const fastf_t *eye)
 
void deering_persp_mat (fastf_t *m, const fastf_t *l, const fastf_t *h, const fastf_t *eye)
 
void quat_mat2quat (quat_t quat, const mat_t mat)
 Quaternion math routines. More...
 
void quat_quat2mat (mat_t mat, const quat_t quat)
 Convert Quaternion to Matrix. More...
 
double quat_distance (const quat_t q1, const quat_t q2)
 Gives the euclidean distance between two quaternions. More...
 
void quat_double (quat_t qout, const quat_t q1, const quat_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. More...
 
void quat_bisect (quat_t qout, const quat_t q1, const quat_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]. More...
 
void quat_slerp (quat_t qout, const quat_t q1, const quat_t q2, double f)
 Do Spherical Linear Interpolation between two unit quaternions by the given factor. More...
 
void quat_sberp (quat_t qout, const quat_t q1, const quat_t qa, const quat_t qb, const quat_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. More...
 
void quat_make_nearest (quat_t q1, const quat_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). More...
 
void quat_print (const char *title, const quat_t quat)
 
void quat_exp (quat_t out, const quat_t in)
 Exponentiate a quaternion, assuming that the scalar part is 0. Code by Ken Shoemake. More...
 
void quat_log (quat_t out, const quat_t in)
 Take the natural logarithm of a unit quaternion. Code by Ken Shoemake. More...
 
void bn_mat_mul (register mat_t o, register const mat_t a, register const mat_t b)
 
void bn_mat_mul2 (register const mat_t i, register mat_t o)
 
void bn_matXvec (register vect_t ov, register const mat_t im, register const vect_t iv)
 
void bn_mat_inv (register mat_t output, const mat_t input)
 
int bn_mat_inverse (register mat_t output, const mat_t input)
 
void bn_vtoh_move (register vect_t h, register const vect_t v)
 
void bn_htov_move (register vect_t v, register const vect_t h)
 
void bn_mat_trn (mat_t om, register const mat_t im)
 
void bn_mat_ae (register fastf_t *m, double azimuth, double elev)
 
void bn_aet_vec (fastf_t *az, fastf_t *el, fastf_t *twist, fastf_t *vec_ae, fastf_t *vec_twist, fastf_t accuracy)
 
void bn_mat_angles (register fastf_t *mat, double alpha_in, double beta_in, double ggamma_in)
 
void bn_mat_angles_rad (register mat_t mat, double alpha, double beta, double ggamma)
 
void bn_eigen2x2 (fastf_t *val1, fastf_t *val2, fastf_t *vec1, fastf_t *vec2, fastf_t a, fastf_t b, fastf_t c)
 
void bn_mat_xrot (fastf_t *m, double sinx, double cosx)
 
void bn_mat_yrot (fastf_t *m, double siny, double cosy)
 
void bn_mat_zrot (fastf_t *m, double sinz, double cosz)
 
void bn_vec_ortho (register vect_t out, register const vect_t in)
 
void quat_mat2quat (register fastf_t *quat, register const fastf_t *mat)
 
void quat_quat2mat (register fastf_t *mat, register const fastf_t *quat)
 
double quat_distance (const fastf_t *q1, const fastf_t *q2)
 
void quat_double (fastf_t *qout, const fastf_t *q1, const fastf_t *q2)
 
void quat_bisect (fastf_t *qout, const fastf_t *q1, const fastf_t *q2)
 
void quat_slerp (fastf_t *qout, const fastf_t *q1, const fastf_t *q2, double f)
 
void quat_sberp (fastf_t *qout, const fastf_t *q1, const fastf_t *qa, const fastf_t *qb, const fastf_t *q2, double f)
 
void quat_make_nearest (fastf_t *q1, const fastf_t *q2)
 
void quat_print (const char *title, const fastf_t *quat)
 
void quat_exp (fastf_t *out, const fastf_t *in)
 
void quat_log (fastf_t *out, const fastf_t *in)
 

Variables

const mat_t bn_mat_identity
 Matrix and vector functionality. More...
 
const mat_t bn_mat_identity = MAT_INIT_IDN
 Matrix and vector functionality. More...
 

Detailed Description

Macro Definition Documentation

#define bn_mat_zero (   _m)
Value:
{ \
bu_log("%s:%d bn_mat_zero() is deprecated, use MAT_ZERO()\n", \
__FILE__, __LINE__); \
(_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; }
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176

Definition at line 66 of file mat.h.

#define bn_mat_idn (   _m)
Value:
{ \
bu_log("%s:%d bn_mat_idn() is deprecated, use MAT_IDN()\n", \
__FILE__, __LINE__); \
(_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; }
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176

Definition at line 76 of file mat.h.

#define bn_mat_copy (   _d,
  _s 
)
Value:
{ \
bu_log("%s:%d bn_mat_copy() is deprecated, use MAT_COPY()\n", \
__FILE__, __LINE__); \
(_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]; }
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176

Definition at line 87 of file mat.h.

Function Documentation

void bn_mat_print ( const char *  title,
const mat_t  m 
)
void bn_mat_print_guts ( const char *  title,
const mat_t  m,
char *  buf,
int  buflen 
)

Definition at line 50 of file mat.c.

References bu_strlcat.

Referenced by bn_mat_print(), bn_mat_print_vls(), and bn_tcl_mat_print().

void bn_mat_print_vls ( const char *  title,
const mat_t  m,
struct bu_vls vls 
)

Definition at line 91 of file mat.c.

References bn_mat_print_guts(), and bu_vls_printf().

Referenced by summary_reports().

Here is the call graph for this function:

double bn_atan2 ( double  x,
double  y 
)

A wrapper for the system atan2(). On the Silicon Graphics, and perhaps on others, x==0 incorrectly returns infinity.

Definition at line 104 of file mat.c.

Referenced by bn_ae_vec(), bn_aet_vec(), rt_ell_uv(), rt_metaball_uv(), rt_part_uv(), and rt_sph_uv().

void bn_mat_mul ( mat_t  o,
const mat_t  a,
const mat_t  b 
)

Multiply matrix "a" by "b" and store the result in "o".

This is different from multiplying "b" by "a" (most of the time!) Also, "o" must not be the same as either of the inputs.

Referenced by _ged_do_rot(), bn_math_cmd(), bn_vlist_3string(), combmem_assemble_mat(), combmem_set_tra(), db_apply_state_from_memb(), db_do_anim(), db_follow_path(), db_tree_mul_dbleaf(), dl_png(), dm_osgLoadMatrix(), dsp_get_data(), edit_translate(), ged_ocenter(), ged_orotate(), ged_oscale(), ged_otranslate(), ged_view_update(), go_draw_solid(), noise_setup(), rt_arb_mirror(), rt_arbn_mirror(), rt_ars_mirror(), rt_bot_mirror(), rt_comb_import4(), rt_comb_import5(), rt_comb_mirror(), rt_dsp_mirror(), rt_ebm_import4(), rt_ebm_import5(), rt_ebm_mirror(), rt_ehy_curve(), rt_ehy_prep(), rt_ehy_tess(), rt_ell_brep(), rt_ell_mirror(), rt_ell_prep(), rt_ell_tess(), rt_ell_tnurb(), rt_epa_curve(), rt_epa_mirror(), rt_epa_prep(), rt_eto_mirror(), rt_grip_mirror(), rt_half_mirror(), rt_hrt_prep(), rt_hyp_mirror(), rt_joint_mirror(), rt_joint_process_selection(), rt_linear_pipe_prep(), rt_nmg_mirror(), rt_nurb_mirror(), rt_part_prep(), rt_part_tess(), rt_particle_mirror(), rt_pipe_mirror(), rt_poly_mirror(), rt_rec_prep(), rt_rhc_mirror(), rt_rhc_prep(), rt_rpc_mirror(), rt_rpc_prep(), rt_shader_mat(), rt_superell_brep(), rt_superell_mirror(), rt_superell_prep(), rt_tgc_curve(), rt_tgc_mirror(), rt_tgc_prep(), rt_tgc_tnurb(), rt_tor_mirror(), rt_vol_import4(), rt_vol_import5(), rt_vol_mirror(), scloud_setup(), setup(), tables_new(), tp_3axis(), tp_3symbol(), vo_rot(), and vo_update().

void bn_mat_mul2 ( const mat_t  i,
mat_t  o 
)

o = i * o

A convenience wrapper for bn_mat_mul() to update a matrix in place. The argument ordering is confusing either way.

Referenced by _ged_do_rot(), _ged_mat_aet(), noise_setup(), pull_comb(), scloud_setup(), setup(), vo_mat_aet(), and vo_rot().

void bn_mat_mul3 ( mat_t  o,
const mat_t  a,
const mat_t  b,
const mat_t  c 
)

o = a * b * c

The output matrix may be the same as 'b' or 'c', but may not be 'a'.

Definition at line 156 of file mat.c.

References bn_mat_mul().

Referenced by bn_wrt_point_direc().

Here is the call graph for this function:

void bn_mat_mul4 ( mat_t  o,
const mat_t  a,
const mat_t  b,
const mat_t  c,
const mat_t  d 
)

o = a * b * c * d

The output matrix may be the same as any input matrix.

Definition at line 166 of file mat.c.

References bn_mat_mul(), and OSL::Strings::u.

Referenced by bn_wrt_point_direc(), and rt_revolve_brep().

Here is the call graph for this function:

void bn_matXvec ( hvect_t  ov,
const mat_t  im,
const hvect_t  iv 
)

Multiply the matrix "im" by the vector "iv" and store the result in the vector "ov". Note this is post-multiply, and operates on 4-tuples. Use MAT4X3VEC() to operate on 3-tuples.

Referenced by bn_math_cmd().

int bn_mat_inverse ( mat_t  output,
const mat_t  input 
)

The matrix pointed at by "input" is inverted and stored in the area pointed at by "output".

Invert a 4-by-4 matrix using Algorithm 120 from ACM. This is a modified Gauss-Jordan algorithm. Note: Inversion is done in place, with 3 work vectors.

Returns
1 if OK.
0 if matrix is singular.

Referenced by pull_comb(), and rt_bend_pipe_prep().

void bn_vtoh_move ( vect_t  h,
const vect_t  v 
)

Takes a pointer to a [x, y, z] vector, and a pointer to space for a homogeneous vector [x, y, z, w], and builds [x, y, z, 1].

void bn_htov_move ( vect_t  v,
const vect_t  h 
)

Takes a pointer to [x, y, z, w], and converts it to an ordinary vector [x/w, y/w, z/w]. Optimization for the case of w==1 is performed.

FIXME: make tolerance configurable

void bn_mat_ae ( mat_t  m,
double  azimuth,
double  elev 
)

Compute a 4x4 rotation matrix given Azimuth and Elevation.

Azimuth is +X, Elevation is +Z, both in degrees.

Formula due to Doug Gwyn, BRL.

Referenced by bn_math_cmd().

void bn_ae_vec ( fastf_t azp,
fastf_t elp,
const vect_t  v 
)

Find the azimuth and elevation angles that correspond to the direction (not including twist) given by a direction vector.

Definition at line 374 of file mat.c.

References bn_atan2(), X, Y, and Z.

Referenced by bn_aet_vec(), bn_math_cmd(), db_tree_describe(), db_tree_flatten_describe(), ged_lookat(), and vo_lookat_cmd().

Here is the call graph for this function:

void bn_aet_vec ( fastf_t az,
fastf_t el,
fastf_t twist,
vect_t  vec_ae,
vect_t  vec_twist,
fastf_t  accuracy 
)

Find the azimuth, elevation, and twist from two vectors. Vec_ae is in the direction of view (+z in mged view) and vec_twist points to the viewers right (+x in mged view). Accuracy (degrees) is used to stabilize flutter between equivalent extremes of atan2(), and to snap twist to zero when elevation is near +/- 90

Referenced by bn_math_cmd(), ged_view_update(), and vo_update().

void bn_vec_ae ( vect_t  vec,
fastf_t  az,
fastf_t  el 
)

Find a unit vector from the origin given azimuth and elevation.

Definition at line 433 of file mat.c.

References VSET.

void bn_vec_aed ( vect_t  vec,
fastf_t  az,
fastf_t  el,
fastf_t  dist 
)

Find a vector from the origin given azimuth, elevation, and distance.

Definition at line 446 of file mat.c.

References VSET.

void bn_mat_angles ( mat_t  mat,
double  alpha,
double  beta,
double  ggamma 
)

This routine builds a Homogeneous rotation matrix, given alpha, beta, and gamma as angles of rotation, in degrees.

Alpha is angle of rotation about the X axis, and is done third. Beta is angle of rotation about the Y axis, and is done second. Gamma is angle of rotation about Z axis, and is done first.

FIXME: make tolerance configurable

Referenced by _ged_mat_aet(), bn_math_cmd(), bn_vlist_2string(), combmem_set_rot(), db_parse_1anim(), ged_orotate(), ged_protate(), ged_qvrot(), ged_rot_args(), ged_rotate_arb_face(), ged_setview(), PL_FORTRAN(), setDirection(), tp_2symbol(), vo_mat_aet(), vo_mrot_cmd(), vo_rot_cmd(), vo_setview(), vo_vrot_cmd(), and wood_setup_2().

void bn_mat_angles_rad ( mat_t  mat,
double  alpha,
double  beta,
double  ggamma 
)

This routine builds a Homogeneous rotation matrix, given alpha, beta, and gamma as angles of rotation, in radians.

Alpha is angle of rotation about the X axis, and is done third. Beta is angle of rotation about the Y axis, and is done second. Gamma is angle of rotation about Z axis, and is done first.

FIXME: make tolerance configurable

void bn_eigen2x2 ( fastf_t val1,
fastf_t val2,
vect_t  vec1,
vect_t  vec2,
fastf_t  a,
fastf_t  b,
fastf_t  c 
)

Find the eigenvalues and eigenvectors of a symmetric 2x2 matrix. (a b) (b c)

The eigenvalue with the smallest absolute value is returned in val1, with its eigenvector in vec1.

Referenced by bn_math_cmd(), rt_ehy_curve(), rt_ell_curve(), rt_epa_curve(), and rt_tgc_curve().

void bn_vec_perp ( vect_t  new_vec,
const vect_t  old_vec 
)

Given a vector, create another vector which is perpendicular to it. The output vector will have unit length only if the input vector did.

FIXME: make tolerance configurable

Definition at line 616 of file mat.c.

References VSETALL, X, Y, Z, and ZERO.

Referenced by bn_mat_fromto(), bn_math_cmd(), go_dm_draw_arrows(), nmg_eu_2vecs_perp(), nmg_to_tgc(), rt_grp_plot(), rt_hlf_plot(), rt_hlf_prep(), and rt_part_plot().

void bn_mat_fromto ( mat_t  m,
const fastf_t from,
const fastf_t to,
const struct bn_tol tol 
)

Given two vectors, compute a rotation matrix that will transform space by the angle between the two. There are many candidate matrices.

The input 'from' and 'to' vectors need not be unit length. MAT4X3VEC(to, m, from) is the identity that is created.

The method used here is from Graphics Gems, A. Glassner, ed. page 531, "The Use of Coordinate Frames in Computer Graphics", by Ken Turkowski, Example 6.

Definition at line 639 of file mat.c.

References A, bn_lseg3_lseg3_parallel(), bn_mat_mul(), bn_mat_trn(), bn_vec_perp(), bu_log(), M, N, Q, R, SMALL_FASTF, UNLIKELY, V3ARGS, VSET, X, Y, and Z.

Referenced by _ged_cm_lookat_pt(), bn_math_cmd(), bn_wrt_point_direc(), nmg_flatten_face(), nmg_isect2d_prep(), nmg_loop_plane_area2(), rt_extrude_bbox(), rt_extrude_prep(), and rt_part_tess().

Here is the call graph for this function:

void bn_mat_xrot ( mat_t  m,
double  sinx,
double  cosx 
)

Given the sin and cos of an X rotation angle, produce the rotation matrix.

Referenced by bn_math_cmd().

void bn_mat_yrot ( mat_t  m,
double  siny,
double  cosy 
)

Given the sin and cos of a Y rotation angle, produce the rotation matrix.

Referenced by bn_math_cmd().

void bn_mat_zrot ( mat_t  m,
double  sinz,
double  cosz 
)

Given the sin and cos of a Z rotation angle, produce the rotation matrix.

Referenced by _ged_mat_aet(), bn_math_cmd(), and vo_mat_aet().

void bn_mat_lookat ( mat_t  rot,
const vect_t  dir,
int  yflip 
)

Given a direction vector D of unit length, product a matrix which rotates that vector D onto the -Z axis. This matrix will be suitable for use as a "model2view" matrix.

XXX This routine will fail if the vector is already more or less aligned with the Z axis.

This is done in several steps.

1 1) Rotate D about Z to match +X axis. Azimuth adjustment.
2 2) Rotate D about Y to match -Y axis. Elevation adjustment.
3 3) Rotate D about Z to make projection of X axis again point
4 in the +X direction. Twist adjustment.
5 4) Optionally, flip sign on Y axis if original Z becomes inverted.
6 This can be nice for static frames, but is astonishing when
7 used in animation.

Definition at line 785 of file mat.c.

References bn_mat_mul(), bn_mat_yrot(), bn_mat_zrot(), bu_log(), V3ARGS, VPRINT, VSET, X, Y, and Z.

Referenced by bn_math_cmd().

Here is the call graph for this function:

int bn_mat_scale_about_pt ( mat_t  mat,
const point_t  pt,
const double  scale 
)

Build a matrix to scale uniformly around a given point.

Returns
-1 if scale is too small.
0 if OK.

FIXME: make tolerance configurable

Definition at line 884 of file mat.c.

References bn_mat_mul(), s, and ZERO.

Referenced by bn_mat_scale_about_pt_wrapper(), db_parse_1anim(), and ged_oscale().

Here is the call graph for this function:

void bn_mat_xform_about_pt ( mat_t  mat,
const mat_t  xform,
const point_t  pt 
)

Build a matrix to apply arbitrary 4x4 transformation around a given point.

Definition at line 909 of file mat.c.

References bn_mat_mul().

Referenced by _ged_do_rot(), bn_math_cmd(), combmem_assemble_mat(), combmem_set_rot(), ged_orotate(), and vo_rot().

Here is the call graph for this function:

int bn_mat_is_equal ( const mat_t  a,
const mat_t  b,
const struct bn_tol tol 
)
Returns
0 When matrices are not equal
1 When matrices are equal

Definition at line 925 of file mat.c.

References BN_CK_TOL, bn_tol::dist, NEAR_ZERO, and bn_tol::perp.

Referenced by _rt_find_identical_solid(), _rt_gettree_leaf(), add_comb_child(), shoot_and_plot(), and unprep_leaf().

int bn_mat_is_identity ( const mat_t  m)

This routine is intended for detecting identity matrices read in from ascii or binary files, where the numbers are pure ones or zeros. This routine is not intended for tolerance-based "near-zero" comparisons; as such, it shouldn't be used on matrices which are the result of calculation.

Returns
0 non-identity
1 a perfect identity matrix

Definition at line 980 of file mat.c.

References bn_mat_identity.

Referenced by _ged_vls_print_matrix(), conv_tree(), db_tree_counter(), db_tree_parse(), ged_arced(), ged_copymat(), mk_tree_gift(), mk_tree_pure(), rt_arbn_import5(), rt_comb_import4(), rt_comb_import5(), and rt_comb_v5_serialize().

void bn_mat_arb_rot ( mat_t  m,
const point_t  pt,
const vect_t  dir,
const fastf_t  ang 
)

Construct a transformation matrix for rotation about an arbitrary axis. The axis is defined by a point (pt) and a unit direction vector (dir). The angle of rotation is "ang"

FIXME: make tolerance configurable

Definition at line 987 of file mat.c.

References bn_mat_mul(), bn_mat_mul2(), X, Y, Z, and ZERO.

Referenced by bbd_setup(), bn_math_cmd(), combmem_set_arb_rot(), ged_arot_args(), rt_arb_mirror(), rt_arbn_mirror(), rt_ars_mirror(), rt_bot_mirror(), rt_comb_mirror(), rt_dsp_mirror(), rt_ebm_mirror(), rt_ell_mirror(), rt_epa_mirror(), rt_eto_mirror(), rt_grip_mirror(), rt_half_mirror(), rt_hyp_mirror(), rt_joint_mirror(), rt_joint_process_selection(), rt_nmg_mirror(), rt_nurb_mirror(), rt_particle_mirror(), rt_pipe_mirror(), rt_poly_mirror(), rt_rhc_mirror(), rt_rpc_mirror(), rt_superell_mirror(), rt_tgc_mirror(), rt_tor_mirror(), rt_vol_mirror(), tesselate_pipe_bend(), and vo_arot_cmd().

Here is the call graph for this function:

matp_t bn_mat_dup ( const mat_t  in)

Return a pointer to a copy of the matrix in dynamically allocated memory.

Definition at line 1046 of file mat.c.

References BU_ALLOC, and out.

Referenced by db_dup_subtree(), db_tree_mul_dbleaf(), db_tree_parse(), ged_arced(), ged_copymat(), mk_tree_gift(), mk_tree_pure(), rt_comb_import4(), and rt_comb_import5().

int bn_mat_ck ( const char *  title,
const mat_t  m 
)

Check to ensure that a rotation matrix preserves axis perpendicularity. Note that not all matrices are rotation matrices.

Returns
-1 FAIL
0 OK

Definition at line 1058 of file mat.c.

References A, chull3d_data::B, bn_mat_print(), bu_bomb(), bu_debug, BU_DEBUG_COREDUMP, BU_DEBUG_MATH, bu_log(), C, and NEAR_ZERO.

Referenced by combmem_disassemble_mat(), combmem_set(), db_recurse(), and db_tree_parse().

Here is the call graph for this function:

fastf_t bn_mat_det3 ( const mat_t  m)

Calculates the determinant of the 3X3 "rotation" part of the passed matrix.

Definition at line 1104 of file mat.c.

fastf_t bn_mat_determinant ( const mat_t  m)

Calculates the determinant of the 4X4 matrix

Definition at line 1117 of file mat.c.

Referenced by bn_isect_planes(), nmg_calc_face_plane(), nmg_snurb_is_planar(), rt_ebm_surf_area(), rt_vol_surf_area(), and rt_vol_volume().

int bn_mat_is_non_unif ( const mat_t  m)

FIXME: make tolerance configurable

Definition at line 1146 of file mat.c.

References ZERO.

Referenced by rt_tor_import5().

void bn_wrt_point_direc ( mat_t  out,
const mat_t  change,
const mat_t  in,
const point_t  point,
const vect_t  direc,
const struct bn_tol tol 
)

Given a model-space transformation matrix "change", return a matrix which applies the change with-respect-to given "point" and "direc".

Definition at line 1169 of file mat.c.

References bn_mat_fromto(), bn_mat_inv(), bn_mat_mul3(), bn_mat_mul4(), and VSET.

Here is the call graph for this function:

void persp_mat ( mat_t  m,
fastf_t  fovy,
fastf_t  aspect,
fastf_t  near1,
fastf_t  far1,
fastf_t  backoff 
)

Definition at line 1209 of file mat.c.

References bn_mat_mul().

Referenced by dl_png(), ged_perspective(), and vo_perspective_cmd().

Here is the call graph for this function:

void mike_persp_mat ( fastf_t pmat,
const fastf_t eye 
)

Definition at line 1243 of file mat.c.

References bn_mat_mul(), NEAR_ZERO, SMALL, VPRINT, X, Y, and Z.

Referenced by ged_eye_pos(), and vo_eye_pos_cmd().

Here is the call graph for this function:

void deering_persp_mat ( fastf_t m,
const fastf_t l,
const fastf_t h,
const fastf_t eye 
)

Definition at line 1312 of file mat.c.

References X, Y, and Z.

Referenced by dl_png().

void quat_mat2quat ( quat_t  quat,
const mat_t  mat 
)

Quaternion math routines.

Unit Quaternions: Q = [ r, a ] where r = cos(theta/2) = rotation amount |a| = sin(theta/2) = rotation axis

If a = 0 we have the reals; if one coord is zero we have complex numbers (2D rotations).

[r, a][s, b] = [rs - a.b, rb + sa + axb]

 -1

[r, a] = (r - a) / (r^2 + a.a)

Powers of quaternions yield incremental rotations, e.g. Q^3 is rotated three times as far as Q.

Some operations on quaternions: -1 [0, P'] = Q [0, P]Q Rotate a point P by quaternion Q -1 a slerp(Q, R, a) = Q(Q R) Spherical linear interp: 0 < a < 1

bisect(P, Q) = (P + Q) / |P + Q| Great circle bisector

Additions inspired by "Quaternion Calculus For Animation" by Ken Shoemake, SIGGRAPH '89 course notes for "Math for SIGGRAPH", May 1989.

Convert Matrix to Quaternion.

Referenced by _ged_rt_write(), bn_math_cmd(), dm_osgLoadMatrix(), ged_get_eyemodel(), ged_quat(), ged_rtwizard(), and test_quat_mat2quat().

void quat_quat2mat ( mat_t  mat,
const quat_t  quat 
)

Convert Quaternion to Matrix.

NB: This only works for UNIT quaternions. We may get imaginary results otherwise. We should normalize first (still yields same rotation).

Referenced by _ged_cm_orientation(), bn_math_cmd(), dm_osgLoadMatrix(), ged_orient(), ged_pov(), ged_quat(), test_quat_quat2mat(), vo_orientation_cmd(), and vo_pov_cmd().

double quat_distance ( const quat_t  q1,
const quat_t  q2 
)

Gives the euclidean distance between two quaternions.

Referenced by bn_quat_distance_wrapper(), and test_quat_distance().

void quat_double ( quat_t  qout,
const quat_t  q1,
const quat_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.

Referenced by bn_math_cmd(), and test_quat_double().

void quat_bisect ( quat_t  qout,
const quat_t  q1,
const quat_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].

Referenced by bn_math_cmd(), and test_quat_bisect().

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

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

As f goes from 0 to 1, qout goes from q1 to q2. Code based on code by Ken Shoemake

Referenced by bn_math_cmd(), and test_quat_slerp().

void quat_sberp ( quat_t  qout,
const quat_t  q1,
const quat_t  qa,
const quat_t  qb,
const quat_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.

Uses the method of successive bisection.

Referenced by bn_math_cmd(), and test_quat_sberp().

void quat_make_nearest ( quat_t  q1,
const quat_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).

Note that smallest euclidian distance implies smallest great circle distance as well (since surface is convex).

Referenced by bn_math_cmd(), and test_quat_make_nearest().

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

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

Referenced by bn_math_cmd(), and test_quat_exp().

void quat_log ( quat_t  out,
const quat_t  in 
)

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

Referenced by bn_math_cmd(), and test_quat_log().

void bn_mat_mul ( register mat_t  o,
register const mat_t  a,
register const mat_t  b 
)
void bn_mat_mul2 ( register const mat_t  i,
register mat_t  o 
)

Definition at line 146 of file mat.c.

References bn_mat_mul().

Referenced by bn_mat_arb_rot().

Here is the call graph for this function:

void bn_matXvec ( register vect_t  ov,
register const mat_t  im,
register const vect_t  iv 
)

Definition at line 182 of file mat.c.

void bn_mat_inv ( register mat_t  output,
const mat_t  input 
)

Definition at line 204 of file mat.c.

References bn_mat_inverse(), bn_mat_print(), bu_bomb(), bu_debug, BU_DEBUG_MATH, and bu_log().

Referenced by bn_wrt_point_direc().

Here is the call graph for this function:

int bn_mat_inverse ( register mat_t  output,
const mat_t  input 
)

Definition at line 219 of file mat.c.

References chull3d_data::b, chull3d_data::p, and ZERO.

Referenced by bn_mat_inv().

void bn_vtoh_move ( register vect_t  h,
register const vect_t  v 
)

Definition at line 307 of file mat.c.

void bn_htov_move ( register vect_t  v,
register const vect_t  h 
)

Definition at line 315 of file mat.c.

References bu_log(), and ZERO.

Here is the call graph for this function:

void bn_mat_trn ( mat_t  om,
register const mat_t  im 
)

Definition at line 333 of file mat.c.

Referenced by bn_mat_fromto().

void bn_mat_ae ( register fastf_t m,
double  azimuth,
double  elev 
)

Definition at line 340 of file mat.c.

void bn_aet_vec ( fastf_t az,
fastf_t el,
fastf_t twist,
fastf_t vec_ae,
fastf_t vec_twist,
fastf_t  accuracy 
)

Definition at line 390 of file mat.c.

References bn_ae_vec(), bn_atan2(), NEAR_ZERO, VSET, X, and Y.

Here is the call graph for this function:

void bn_mat_angles ( register fastf_t mat,
double  alpha_in,
double  beta_in,
double  ggamma_in 
)

Definition at line 458 of file mat.c.

References OSL::Strings::alpha, NEAR_ZERO, and ZERO.

void bn_mat_angles_rad ( register mat_t  mat,
double  alpha,
double  beta,
double  ggamma 
)

Definition at line 523 of file mat.c.

References ZERO.

void bn_eigen2x2 ( fastf_t val1,
fastf_t val2,
fastf_t vec1,
fastf_t vec2,
fastf_t  a,
fastf_t  b,
fastf_t  c 
)

Definition at line 565 of file mat.c.

References NEAR_ZERO, VSET, X, and Y.

void bn_mat_xrot ( fastf_t m,
double  sinx,
double  cosx 
)

Definition at line 716 of file mat.c.

void bn_mat_yrot ( fastf_t m,
double  siny,
double  cosy 
)

Definition at line 739 of file mat.c.

Referenced by bn_mat_lookat().

void bn_mat_zrot ( fastf_t m,
double  sinz,
double  cosz 
)

Definition at line 762 of file mat.c.

Referenced by bn_mat_lookat().

void bn_vec_ortho ( register vect_t  out,
register const vect_t  in 
)

Definition at line 840 of file mat.c.

References bu_log(), NEAR_ZERO, SQRT_SMALL_FASTF, UNLIKELY, V3ARGS, VSETALL, X, Y, Z, and ZERO.

Here is the call graph for this function:

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

Definition at line 65 of file qmath.c.

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

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

Definition at line 125 of file qmath.c.

References X, Y, and Z.

double quat_distance ( const fastf_t q1,
const fastf_t q2 
)

Definition at line 152 of file qmath.c.

Referenced by quat_make_nearest().

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

Definition at line 162 of file qmath.c.

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

Definition at line 175 of file qmath.c.

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

Definition at line 183 of file qmath.c.

References M_PI, X, Y, and Z.

Referenced by quat_sberp().

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

Definition at line 228 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 
)

Definition at line 247 of file qmath.c.

References quat_distance().

Here is the call graph for this function:

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

Definition at line 265 of file qmath.c.

References X, Y, and Z.

void quat_exp ( fastf_t out,
const fastf_t in 
)

Definition at line 284 of file qmath.c.

void quat_log ( fastf_t out,
const fastf_t in 
)

Definition at line 300 of file qmath.c.

Variable Documentation

const mat_t bn_mat_identity

Matrix and vector functionality.

Definition at line 46 of file mat.c.

Referenced by _rt_gettree_leaf(), bn_mat_is_identity(), brep_conversion_tree(), conv_tree(), db_tree_describe(), db_tree_flatten_describe(), ged_analyze(), ged_arced(), ged_bot(), ged_bot_condense(), ged_bot_face_fuse(), ged_bot_face_sort(), ged_bot_flip(), ged_bot_fuse(), ged_bot_merge(), ged_bot_split(), ged_bot_sync(), ged_bot_vertex_fuse(), ged_brep(), ged_copyeval(), ged_decompose(), ged_fracture(), ged_inside(), ged_joint2(), ged_nmg_fix_normals(), ged_nmg_simplify(), ged_pathsum(), ged_perspective(), ged_shells(), ged_tables(), light_setup(), rt_arb_import4(), rt_arb_import5(), rt_arbn_import4(), rt_ars_import4(), rt_ars_import5(), rt_bot_import4(), rt_bot_import5(), rt_cline_import4(), rt_cline_import5(), rt_comb_export4(), rt_db_external5_to_internal5(), rt_db_get_internal(), rt_dsp_import4(), rt_dsp_import5(), rt_ebm_import4(), rt_ebm_import5(), rt_ehy_import4(), rt_ehy_import5(), rt_ell_import4(), rt_ell_import5(), rt_epa_import4(), rt_epa_import5(), rt_eto_import4(), rt_eto_import5(), rt_extrude_import4(), rt_extrude_import5(), rt_grp_import4(), rt_grp_import5(), rt_hf_import4(), rt_hlf_import4(), rt_hlf_import5(), rt_hrt_import5(), rt_hyp_import5(), rt_joint_import5(), rt_metaball_import5(), rt_nurb_import4(), rt_nurb_import5(), rt_part_import4(), rt_part_import5(), rt_pg_import4(), rt_pipe_import4(), rt_pipe_import5(), rt_pnts_import5(), rt_revolve_import5(), rt_rhc_import4(), rt_rhc_import5(), rt_rpc_import4(), rt_rpc_import5(), rt_sketch_import4(), rt_sketch_import5(), rt_submodel_import4(), rt_submodel_import5(), rt_superell_import4(), rt_superell_import5(), rt_tgc_import4(), rt_tgc_import5(), rt_tor_import4(), rt_tor_import5(), rt_vol_import4(), rt_vol_import5(), rt_xxx_import5(), shoot_and_plot(), and unprep_leaf().

const mat_t bn_mat_identity = MAT_INIT_IDN

Matrix and vector functionality.

Definition at line 46 of file mat.c.

Referenced by _rt_gettree_leaf(), bn_mat_is_identity(), brep_conversion_tree(), conv_tree(), db_tree_describe(), db_tree_flatten_describe(), ged_analyze(), ged_arced(), ged_bot(), ged_bot_condense(), ged_bot_face_fuse(), ged_bot_face_sort(), ged_bot_flip(), ged_bot_fuse(), ged_bot_merge(), ged_bot_split(), ged_bot_sync(), ged_bot_vertex_fuse(), ged_brep(), ged_copyeval(), ged_decompose(), ged_fracture(), ged_inside(), ged_joint2(), ged_nmg_fix_normals(), ged_nmg_simplify(), ged_pathsum(), ged_perspective(), ged_shells(), ged_tables(), light_setup(), rt_arb_import4(), rt_arb_import5(), rt_arbn_import4(), rt_ars_import4(), rt_ars_import5(), rt_bot_import4(), rt_bot_import5(), rt_cline_import4(), rt_cline_import5(), rt_comb_export4(), rt_db_external5_to_internal5(), rt_db_get_internal(), rt_dsp_import4(), rt_dsp_import5(), rt_ebm_import4(), rt_ebm_import5(), rt_ehy_import4(), rt_ehy_import5(), rt_ell_import4(), rt_ell_import5(), rt_epa_import4(), rt_epa_import5(), rt_eto_import4(), rt_eto_import5(), rt_extrude_import4(), rt_extrude_import5(), rt_grp_import4(), rt_grp_import5(), rt_hf_import4(), rt_hlf_import4(), rt_hlf_import5(), rt_hrt_import5(), rt_hyp_import5(), rt_joint_import5(), rt_metaball_import5(), rt_nurb_import4(), rt_nurb_import5(), rt_part_import4(), rt_part_import5(), rt_pg_import4(), rt_pipe_import4(), rt_pipe_import5(), rt_pnts_import5(), rt_revolve_import5(), rt_rhc_import4(), rt_rhc_import5(), rt_rpc_import4(), rt_rpc_import5(), rt_sketch_import4(), rt_sketch_import5(), rt_submodel_import4(), rt_submodel_import5(), rt_superell_import4(), rt_superell_import5(), rt_tgc_import4(), rt_tgc_import5(), rt_tor_import4(), rt_tor_import5(), rt_vol_import4(), rt_vol_import5(), rt_xxx_import5(), shoot_and_plot(), and unprep_leaf().