2 * $Source: x:/prj/tech/libsrc/matrix/RCS/matrixd.h $
5 * $Date: 1998/06/18 13:07:01 $
20 // In general these babies take pointers to doubles
21 // (or defined mxd_vector * and mxd_matrix *
22 // normal vecs are 3, mats are 3x3
23 // note that rather than intel I favor src -> dest
24 // self modifiers have the "eq" post on the op.
25 // in don't make dest = src, use the eq function
26 // el means element wise.
27 // coordinates are zero indexed
28 // some functions will be implemented as macros, esp
29 // the eq or non-eq versions of some stuff
31 // These two constructors are mostly for use in constructing matrices and vectors from
32 // constants, but it should be fast and pretty much general purpose. Since these are
33 // macros beware of side effects
36 // PURE VECTOR OPERATIONS
39 void mxd_zero_vec(mxds_vector
*v
);
41 // create a unit vec in row n
42 void mxd_unit_vec(mxds_vector
*v
,int n
);
45 void mxd_copy_vec(mxds_vector
*dest
,const mxds_vector
*src
);
48 void mxd_add_vec(mxds_vector
*dest
, const mxds_vector
*v1
, const mxds_vector
*v2
);
50 void mxd_addeq_vec(mxds_vector
*v1
, const mxds_vector
*v2
);
53 void mxd_sub_vec(mxds_vector
*dest
, const mxds_vector
*v1
, const mxds_vector
*v2
);
55 void mxd_subeq_vec(mxds_vector
*v1
,const mxds_vector
*v2
);
58 void mxd_scale_vec(mxds_vector
*dest
,const mxds_vector
*v
,double s
);
60 void mxd_scaleeq_vec(mxds_vector
*v
,double s
);
63 void mxd_scale_add_vec(mxds_vector
*dest
,const mxds_vector
*v1
,const mxds_vector
*v2
,double s
);
65 void mxd_scale_addeq_vec(mxds_vector
*v1
,const mxds_vector
*v2
,double s
);
67 // basically interpolate between 2 vectors
68 // dest = v1*(1-s) + v2*(s)
69 // s=0 gets you v1, basically
70 void mxd_interpolate_vec(mxds_vector
*dest
,const mxds_vector
*v1
,const mxds_vector
*v2
,double s
);
73 void mxd_div_vec(mxds_vector
*dest
,const mxds_vector
*v
,double s
);
75 void mxd_diveq_vec(mxds_vector
*v
,double s
);
77 // dest = v1 .* v2 // matlab notation
78 void mxd_elmul_vec(mxds_vector
*dest
,const mxds_vector
*v1
,const mxds_vector
*v2
);
80 void mxd_elmuleq_vec(mxds_vector
*v1
,const mxds_vector
*v2
);
83 double mxd_dist2_vec(const mxds_vector
*v1
,const mxds_vector
*v2
);
86 double mxd_dist_vec(const mxds_vector
*v1
,const mxds_vector
*v2
);
89 double mxd_mag2_vec(const mxds_vector
*v
);
92 double mxd_mag_vec(const mxds_vector
*v
);
94 // dest = v1/|v1|, returns |v1|
95 double mxd_norm_vec(mxds_vector
*dest
,const mxds_vector
*v
);
96 // v1 /= |v1|, return |v1|
97 double mxd_normeq_vec(mxds_vector
*v1
);
100 double mxd_dot_vec(const mxds_vector
*v1
,const mxds_vector
*v2
);
103 void mxd_cross_vec(mxds_vector
*dest
,const mxds_vector
*v1
,const mxds_vector
*v2
);
105 // dest = (v1 x v2) / |v1 x v2|, return |v1 x v2|
106 double mxd_cross_norm_vec(mxds_vector
*dest
,const mxds_vector
*v1
, const mxds_vector
*v2
);
109 void mxd_neg_vec(mxds_vector
*dest
,const mxds_vector
*v
);
111 void mxd_negeq_vec(mxds_vector
*v
);
114 void mxd_prn_vec(const mxds_vector
*v
);
116 // A FEW MORE PURE MATRIX OPS
118 // Gives you the minimum x,y,z in the dest
119 void mxd_min_vec(mxds_vector
*dest
,const mxds_vector
*v1
,const mxds_vector
*v2
);
120 void mxd_mineq_vec(mxds_vector
*dest
,const mxds_vector
*v
);
122 // Gives you the maximum x,y,z in the dst
123 void mxd_max_vec(mxds_vector
*dest
,const mxds_vector
*v1
,const mxds_vector
*v2
);
124 void mxd_maxeq_vec(mxds_vector
*dest
,const mxds_vector
*v
);
128 // PURE MATRIX OPERATIONS
129 void mxd_zero_mat(mxds_matrix
*m
);
132 void mxd_identity_mat(mxds_matrix
*m
);
135 void mxd_copy_mat(mxds_matrix
*dest
,const mxds_matrix
*src
);
138 void mxd_scale_mat(mxds_matrix
*dest
,const mxds_matrix
*m
,double s
);
140 void mxd_scaleeq_mat(mxds_matrix
*m
,double s
);
143 void mxd_div_mat(mxds_matrix
*dest
,const mxds_matrix
*m
,double s
);
145 void mxd_diveq_mat(mxds_matrix
*m
,double s
);
148 double mxd_det_mat(const mxds_matrix
*m
);
151 void mxd_trans_mat(mxds_matrix
*dest
,const mxds_matrix
*m
);
153 void mxd_transeq_mat(mxds_matrix
*m
);
155 // dest = m^-1, returns false if matrix degenerate
156 bool mxd_inv_mat(mxds_matrix
*dest
,const mxds_matrix
*m
);
158 bool mxd_inveq_mat(mxds_matrix
*m
);
160 // normalize each column of m
161 void mxd_normcol_mat(mxds_matrix
*dest
,const mxds_matrix
*m
);
162 void mxd_normcoleq_mat(mxds_matrix
*m
);
164 // normalize each row of m
165 void mxd_normrow_mat(mxds_matrix
*dest
,const mxds_matrix
*m
);
166 void mxd_normroweq_mat(mxds_matrix
*m
);
168 // sanitize the matrix, make |m| = 1 no matter what,
169 // trying to preserve geometry
170 bool mxd_sanitize_mat(mxds_matrix
*dest
,const mxds_matrix
*m
,double tol
);
171 bool mxd_sanitizeeq_mat(mxds_matrix
*m
,double tol
);
174 void mxd_mul_mat(mxds_matrix
*dest
,const mxds_matrix
*m1
,const mxds_matrix
*m2
);
176 void mxd_muleq_mat(mxds_matrix
*m1
,const mxds_matrix
*m2
);
179 void mxd_tmul_mat(mxds_matrix
*dest
,const mxds_matrix
*m1
,const mxds_matrix
*m2
);
181 void mxd_tmuleq_mat(const mxds_matrix
*m1
,mxds_matrix
*m2
);
184 void mxd_mult_mat(mxds_matrix
*dest
,const mxds_matrix
*m1
,const mxds_matrix
*m2
);
188 void mxd_elmul_mat(mxds_matrix
*dest
,const mxds_matrix
*m1
,const mxds_matrix
*m2
);
190 void mxd_elmuleq_mat(mxds_matrix
*m1
,const mxds_matrix
*m2
);
193 void mxd_swaprow_mat(mxds_matrix
*dest
,const mxds_matrix
*m1
,int n1
,int n2
);
194 void mxd_swaproweq_mat(mxds_matrix
*m1
,int n1
,int n2
);
196 void mxd_swapcol_mat(mxds_matrix
*dest
,const mxds_matrix
*m1
,int n1
,int n2
);
197 void mxd_swapcoleq_mat(mxds_matrix
*m1
,int n1
,int n2
);
200 void mxd_prn_mat(const mxds_matrix
*m
);
204 // Rotates a vector about the appropriate axis.
205 // Put in for Sean. With love, Jaemz
206 // Assumes src and dest are different
207 void mxd_rot_x_vec(mxds_vector
*dst
,const mxds_vector
*src
,mxs_ang ang
);
208 void mxd_rot_y_vec(mxds_vector
*dst
,const mxds_vector
*src
,mxs_ang ang
);
209 void mxd_rot_z_vec(mxds_vector
*dst
,const mxds_vector
*src
,mxs_ang ang
);
213 // convert to and from rads
214 mxs_ang
mxd_rad2ang(double rad
);
215 double mxd_ang2rad(mxs_ang ang
);
217 // convert to and from degs
218 mxs_ang
mxd_deg2ang(double deg
);
219 double mxd_ang2deg(double ang
);
222 // get the sin and cosine out of a mxs_ang
223 // anything else, get it yourself. Weenie
224 double mxd_sin(mxs_ang ang
);
225 double mxd_cos(mxs_ang ang
);
226 void mxd_sincos(mxs_ang ang
,double *s
, double *c
);
228 // create rotation matrices to spin about that axis by ang
229 void mxd_mk_rot_x_mat(mxds_matrix
*m
,mxs_ang ang
);
230 void mxd_mk_rot_y_mat(mxds_matrix
*m
,mxs_ang ang
);
231 void mxd_mk_rot_z_mat(mxds_matrix
*m
,mxs_ang ang
);
233 // create rotation matrix to spin about arbitrary vector by ang
234 void mxd_mk_rot_vec_mat(mxds_matrix
*m
, const mxds_vector
*v
, mxs_ang ang
);
235 // create rotation matrix to take x-axis to unit vecctor v
236 void mxd_mk_move_x_mat(mxds_matrix
*m
, const mxds_vector
*v
);
238 // rotate matrix about that axis in its own frame by ang
239 void mxd_rot_x_mat(mxds_matrix
*dest
,const mxds_matrix
*m
,mxs_ang ang
);
240 void mxd_rot_y_mat(mxds_matrix
*dest
,const mxds_matrix
*m
,mxs_ang ang
);
241 void mxd_rot_z_mat(mxds_matrix
*dest
,const mxds_matrix
*m
,mxs_ang ang
);
243 // and now, lovely rad versions of the above
244 void mxd_mk_rot_x_mat_rad(mxds_matrix
*m
,double ang
);
245 void mxd_mk_rot_y_mat_rad(mxds_matrix
*m
,double ang
);
246 void mxd_mk_rot_z_mat_rad(mxds_matrix
*m
,double ang
);
248 // rotate matrix about that axis in its own frame by ang
249 void mxd_rot_x_mat_rad(mxds_matrix
*dest
,const mxds_matrix
*m
,double ang
);
250 void mxd_rot_y_mat_rad(mxds_matrix
*dest
,const mxds_matrix
*m
,double ang
);
251 void mxd_rot_z_mat_rad(mxds_matrix
*dest
,const mxds_matrix
*m
,double ang
);
253 // Create an orientation matrix from an angvec, using traditional
254 // order of bank around x, pitch around y, heading around z,
255 // all using the right hand rule
256 void mxd_ang2mat(mxds_matrix
*dest
,const mxs_angvec
*a
);
258 // Convert a matrix into angles, using the standard
259 // angle order of roll around x, pitch around y, heading around z
260 void mxd_mat2ang( mxs_angvec
* dest
, const mxds_matrix
* m
);
262 // just like the above, but radians
263 void mxd_mat2rad(mxds_vector
*dest
,const mxds_matrix
*m
);
265 // also just like the above, also in radians;
266 void mxd_rad2mat(mxds_matrix
*dest
,const mxds_vector
*a
);
268 // Print out angvec in hex. 10000 = 2pi
269 void mxd_prn_angvec(const mxs_angvec
*a
);
272 // MIXED MATRIX AND VECTOR OPS
274 // element wise mul of m by v to make different coordinate
277 void mxd_mat_elmul_vec(mxds_matrix
*dest
,const mxds_matrix
*m
,const mxds_vector
*v
);
279 void mxd_mat_elmuleq_vec(mxds_matrix
*m
,const mxds_vector
*v
);
282 void mxd_mat_eltmul_vec(mxds_matrix
*dest
,const mxds_matrix
*m
,const mxds_vector
*v
);
284 void mxd_mat_eltmuleq_vec(mxds_matrix
*m
,const mxds_vector
*v
);
287 void mxd_mat_mul_vec(mxds_vector
*dest
,const mxds_matrix
*m
,const mxds_vector
*v
);
288 // v x= M, this is idiotic, if anyone uses it, I'll kill them
289 void mxd_mat_muleq_vec(const mxds_matrix
*m
,mxds_vector
*v
);
291 // dest = M^t x v, this is for multing by inverse if unit
292 void mxd_mat_tmul_vec(mxds_vector
*dest
,const mxds_matrix
*m
, const mxds_vector
*v
);
294 void mxd_mat_tmuleq_vec(const mxds_matrix
*m
,mxds_vector
*v
);
298 // identity transform
299 void mxd_identity_trans(mxds_trans
*t
);
302 void mxd_copy_trans(mxds_trans
*dest
,const mxds_trans
*src
);
304 // invert transform that is unitary, dest != src
305 void mxd_transpose_trans(mxds_trans
*dest
,const mxds_trans
*src
);
307 // multiply 2 transforms
309 void mxd_mul_trans(mxds_trans
*dest
,const mxds_trans
*t1
,const mxds_trans
*t2
);
311 // transpose pre multiply 2 transforms
312 // for instance, putting view onto a stack
314 void mxd_tmul_trans(mxds_trans
*dest
,const mxds_trans
*t1
,const mxds_trans
*t2
);
316 // transpose post multiply 2 transforms
317 // for instance, putting view onto a stack
319 void mxd_mult_trans(mxds_trans
*dest
,const mxds_trans
*t1
,const mxds_trans
*t2
);
321 // multiply tform by vector
323 void mxd_trans_mul_vec(mxds_vector
*dest
,const mxds_trans
*t
,const mxds_vector
*v
);
325 // inverse multiply tform by vector
327 void mxd_trans_tmul_vec(mxds_vector
*dest
,const mxds_trans
*t
,const mxds_vector
*v
);
330 void mxd_prn_trans(const mxds_trans
*t
);
337 #endif /* __MATRIXD_H */