Complex Numbers
[libbn (numerical functions)]

Collaboration diagram for Complex Numbers:

Data Structures

struct  bn_complex

Files

file  complex.c

Defines

#define bn_cx_copy(ap, bp)   {*(ap) = *(bp);}
#define bn_cx_neg(cp)   { (cp)->re = -((cp)->re);(cp)->im = -((cp)->im);}
#define bn_cx_real(cp)   (cp)->re
#define bn_cx_imag(cp)   (cp)->im
#define bn_cx_add(ap, bp)   { (ap)->re += (bp)->re; (ap)->im += (bp)->im;}
#define bn_cx_ampl(cp)   hypot((cp)->re, (cp)->im)
#define bn_cx_amplsq(cp)   ((cp)->re * (cp)->re + (cp)->im * (cp)->im)
#define bn_cx_conj(cp)   { (cp)->im = -(cp)->im; }
#define bn_cx_cons(cp, r, i)   { (cp)->re = r; (cp)->im = i; }
#define bn_cx_phas(cp)   atan2((cp)->im, (cp)->re)
#define bn_cx_scal(cp, s)   { (cp)->re *= (s); (cp)->im *= (s); }
#define bn_cx_sub(ap, bp)   { (ap)->re -= (bp)->re; (ap)->im -= (bp)->im;}
#define bn_cx_mul(ap, bp)
#define bn_cx_mul2(ap, bp, cp)
#define bn_mat_zero(_m)
#define bn_mat_idn(_m)
#define bn_mat_copy(_d, _s)

Typedefs

typedef struct bn_complex bn_complex_t

Functions

void bn_cx_div (bn_complex_t *ap, const bn_complex_t *bp)
 Divide one complex by another.
void bn_cx_sqrt (bn_complex_t *op, const bn_complex_t *ip)
 Compute square root of complex number.
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 vect_t from, const vect_t to)
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)

Variables

const mat_t bn_mat_identity

Detailed Description


Define Documentation

#define bn_cx_copy ( ap,
bp   )     {*(ap) = *(bp);}

Definition at line 463 of file bn.h.

#define bn_cx_neg ( cp   )     { (cp)->re = -((cp)->re);(cp)->im = -((cp)->im);}

Definition at line 464 of file bn.h.

#define bn_cx_real ( cp   )     (cp)->re

Definition at line 465 of file bn.h.

#define bn_cx_imag ( cp   )     (cp)->im

Definition at line 466 of file bn.h.

#define bn_cx_add ( ap,
bp   )     { (ap)->re += (bp)->re; (ap)->im += (bp)->im;}

Definition at line 468 of file bn.h.

#define bn_cx_ampl ( cp   )     hypot((cp)->re, (cp)->im)

Definition at line 469 of file bn.h.

Referenced by bn_cx_sqrt().

#define bn_cx_amplsq ( cp   )     ((cp)->re * (cp)->re + (cp)->im * (cp)->im)

Definition at line 470 of file bn.h.

#define bn_cx_conj ( cp   )     { (cp)->im = -(cp)->im; }

Definition at line 471 of file bn.h.

#define bn_cx_cons ( cp,
r,
 )     { (cp)->re = r; (cp)->im = i; }

Definition at line 472 of file bn.h.

#define bn_cx_phas ( cp   )     atan2((cp)->im, (cp)->re)

Definition at line 473 of file bn.h.

#define bn_cx_scal ( cp,
 )     { (cp)->re *= (s); (cp)->im *= (s); }

Definition at line 474 of file bn.h.

#define bn_cx_sub ( ap,
bp   )     { (ap)->re -= (bp)->re; (ap)->im -= (bp)->im;}

Definition at line 475 of file bn.h.

#define bn_cx_mul ( ap,
bp   ) 
Value:
{ register fastf_t a__re, b__re; \
        (ap)->re = ((a__re=(ap)->re)*(b__re=(bp)->re)) - (ap)->im*(bp)->im; \
        (ap)->im = a__re*(bp)->im + (ap)->im*b__re; }

Definition at line 477 of file bn.h.

#define bn_cx_mul2 ( ap,
bp,
cp   ) 
Value:
{ \
        (ap)->re = (cp)->re * (bp)->re - (cp)->im * (bp)->im; \
        (ap)->im = (cp)->re * (bp)->im + (cp)->im * (bp)->re; }

Definition at line 483 of file bn.h.

#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; }

Definition at line 529 of file bn.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; }

Definition at line 539 of file bn.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]; }

Definition at line 550 of file bn.h.


Typedef Documentation

typedef struct bn_complex bn_complex_t

"complex number" data type:


Function Documentation

void bn_cx_div ( bn_complex_t ap,
const bn_complex_t bp 
)

Divide one complex by another.

B N _ C X _ D I V bn_cx_div(&a, &b). divides a by b. Zero divisor fails. a and b may coincide. Result stored in a.

void bn_cx_sqrt ( bn_complex_t op,
const bn_complex_t ip 
)

Compute square root of complex number.

B N _ C X _ S Q R T bn_cx_sqrt(&out, &c) replaces out by sqrt(c)

Note: This is a double-valued function; the result of bn_cx_sqrt() always has nonnegative imaginary part.

Definition at line 69 of file complex.c.

References bn_cx_ampl, bn_complex::im, bn_complex::re, and ZERO.

void bn_mat_print ( const char *  title,
const mat_t  m 
)

B N _ M A T _ P R I N T

Definition at line 91 of file mat.c.

References bn_mat_print_guts().

Referenced by bn_mat_ck(), and bn_mat_inv().

Here is the call graph for this function:

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

Definition at line 58 of file mat.c.

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 
)

B N _ M A T _ P R I N T _ V L S

Definition at line 105 of file mat.c.

References bn_mat_print_guts().

Here is the call graph for this function:

double bn_atan2 ( double  y,
double  x 
)

B N _ A T A N 2

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

Definition at line 123 of file mat.c.

References M_PI_2.

Referenced by bn_ae_vec(), and bn_aet_vec().

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 
)

Referenced by bn_mat_arb_rot().

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

B N _ M A T _ M U L 3

o = a * b * c

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

Definition at line 197 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  ao,
const mat_t  a,
const mat_t  b,
const mat_t  c,
const mat_t  d 
)

B N _ M A T _ M U L 4

o = a * b * c * d

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

Definition at line 214 of file mat.c.

References bn_mat_mul().

Referenced by bn_wrt_point_direc().

Here is the call graph for this function:

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

Referenced by bn_math_cmd().

void bn_mat_inv ( mat_t  output,
const mat_t  input 
)
int bn_mat_inverse ( mat_t  output,
const mat_t  input 
)

Referenced by bn_mat_inv().

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 
)

Referenced by bn_mat_fromto(), and bn_math_cmd().

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

Referenced by bn_math_cmd().

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

B N _ A E _ V E C

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

Definition at line 471 of file mat.c.

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

Referenced by bn_aet_vec(), and bn_math_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 
)

Referenced by bn_math_cmd().

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

B N _ V E C _ A E

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

Definition at line 536 of file mat.c.

References VSET, and VUNITIZE.

void bn_vec_aed ( vect_t  vect,
fastf_t  az,
fastf_t  el,
fastf_t  distance 
)

B N _ V E C _ A E D

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

Definition at line 553 of file mat.c.

References VSET.

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 
)

Referenced by bn_math_cmd().

void bn_vec_perp ( vect_t  new,
const vect_t  old 
)

B N _ V E C _ P E R P

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 751 of file mat.c.

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

Referenced by bn_mat_fromto(), and bn_math_cmd().

void bn_mat_fromto ( mat_t  m,
const vect_t  from,
const vect_t  to 
)

B N _ M A T _ F R O M T O

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

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

FIXME: make tolerance configurable

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

Definition at line 782 of file mat.c.

References A, bn_mat_mul(), bn_mat_trn(), bn_vec_perp(), M, MAT4X3VEC, MAT_IDN, N, Q, R, UNLIKELY, V3ARGS, VCROSS, VDOT, VMOVE, VSET, VUNITIZE, X, Y, and Z.

Referenced by bn_math_cmd(), and bn_wrt_point_direc().

Here is the call graph for this function:

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

Referenced by bn_math_cmd().

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

Referenced by bn_mat_lookat(), and bn_math_cmd().

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

Referenced by bn_mat_lookat(), and bn_math_cmd().

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

B N _ M A T _ L O O K A T

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

Definition at line 966 of file mat.c.

References bn_mat_mul(), bn_mat_yrot(), bn_mat_zrot(), MAT4X3VEC, MAT_COPY, MAT_IDN, V3ARGS, VPRINT, VSET, X, x, Y, Z, and z.

Referenced by bn_math_cmd().

Here is the call graph for this function:

void bn_vec_ortho ( vect_t  out,
const vect_t  in 
)

Referenced by bn_math_cmd(), and tp_3vector().

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

B N _ M A T _ S C A L E _ A B O U T _ P T

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 1084 of file mat.c.

References bn_mat_mul(), MAT_DELTAS_VEC, MAT_DELTAS_VEC_NEG, MAT_IDN, MAT_ZERO, and ZERO.

Referenced by bn_mat_scale_about_pt_wrapper().

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 
)

B N _ M A T _ X F O R M _ A B O U T _ P T

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

Definition at line 1115 of file mat.c.

References bn_mat_mul(), MAT_DELTAS_VEC, MAT_DELTAS_VEC_NEG, and MAT_IDN.

Referenced by bn_math_cmd().

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 
)

B N _ M A T _ I S _ E Q U A L

Returns:
0 When matrices are not equal
1 When matricies are equal

Definition at line 1137 of file mat.c.

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

int bn_mat_is_identity ( const mat_t  m  ) 

B N _ M A T _ I S _ I D E N T I T Y

This routine is intended for detecting identity matricies 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 1195 of file mat.c.

References bn_mat_identity.

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

B N _ M A T _ A R B _ R O T

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 1211 of file mat.c.

References bn_mat_mul(), bn_mat_mul2(), MAT_IDN, MDX, MDY, MDZ, X, Y, Z, and ZERO.

Referenced by bn_math_cmd().

Here is the call graph for this function:

matp_t bn_mat_dup ( const mat_t  in  ) 

B N _ M A T _ D U P

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

Definition at line 1272 of file mat.c.

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

B N _ M A T _ C K

Check to ensure that a rotation matrix preserves axis perpendicularily. Note that not all matricies are rotation matricies.

Returns:
-1 FAIL
0 OK

Definition at line 1294 of file mat.c.

References A, bn_mat_print(), NEAR_ZERO, VDIVIDE_TOL, VDOT, and VMOVE.

Here is the call graph for this function:

fastf_t bn_mat_det3 ( const mat_t  m  ) 

B N _ M A T _ D E T 3

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

Definition at line 1345 of file mat.c.

fastf_t bn_mat_determinant ( const mat_t  m  ) 

B N _ M A T _ D E T E R M I N A N T

Calculates the determinant of the 4X4 matrix

Definition at line 1363 of file mat.c.

Referenced by bn_isect_planes().

int bn_mat_is_non_unif ( const mat_t  m  ) 

B N _ M A T _ I S _ N O N _ U N I F

FIXME: make tolerance configurable

Definition at line 1397 of file mat.c.

References MAGSQ, and ZERO.

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

B N _ W R T _ P O I N T _ D I R E C

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

Definition at line 1426 of file mat.c.

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

Here is the call graph for this function:


Variable Documentation

Definition at line 54 of file mat.c.

Referenced by bn_mat_is_identity().

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