convert line ends
[canaan.git] / prj / tech / libsrc / matrix / matrixd.h
blob91cca5674a43192fd57121f1cad0e936bb5b067d
1 /*
2 * $Source: x:/prj/tech/libsrc/matrix/RCS/matrixd.h $
3 * $Revision: 1.22 $
4 * $Author: JAEMZ $
5 * $Date: 1998/06/18 13:07:01 $
6 */
9 #ifndef __MATRIXD_H
10 #define __MATRIXD_H
11 #pragma once
13 #include <matrixds.h>
15 #ifdef __cplusplus
16 extern "C"
18 #endif
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
38 // v = 0
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);
44 // copy a vec
45 void mxd_copy_vec(mxds_vector *dest,const mxds_vector *src);
47 // dest = v1 + v2;
48 void mxd_add_vec(mxds_vector *dest, const mxds_vector *v1, const mxds_vector *v2);
49 // v1 += v2;
50 void mxd_addeq_vec(mxds_vector *v1, const mxds_vector *v2);
52 // dest = v1-v2
53 void mxd_sub_vec(mxds_vector *dest, const mxds_vector *v1, const mxds_vector *v2);
54 // v1 -= v2;
55 void mxd_subeq_vec(mxds_vector *v1,const mxds_vector *v2);
57 // dest = s * v
58 void mxd_scale_vec(mxds_vector *dest,const mxds_vector *v,double s);
59 // v *= s
60 void mxd_scaleeq_vec(mxds_vector *v,double s);
62 // dest = v1 + s * v2
63 void mxd_scale_add_vec(mxds_vector *dest,const mxds_vector *v1,const mxds_vector *v2,double s);
64 // v1 += s * v2
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);
72 // dest = v /s
73 void mxd_div_vec(mxds_vector *dest,const mxds_vector *v,double s);
74 // v /= 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);
79 // v1 .*= v2
80 void mxd_elmuleq_vec(mxds_vector *v1,const mxds_vector *v2);
82 // |v1-v2|^2
83 double mxd_dist2_vec(const mxds_vector *v1,const mxds_vector *v2);
85 // |v1-v2|
86 double mxd_dist_vec(const mxds_vector *v1,const mxds_vector *v2);
88 // |v|^2
89 double mxd_mag2_vec(const mxds_vector *v);
91 // |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);
99 // return v1 . v2
100 double mxd_dot_vec(const mxds_vector *v1,const mxds_vector *v2);
102 // dest = v1 x 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);
108 // dest = -v
109 void mxd_neg_vec(mxds_vector *dest,const mxds_vector *v);
110 // v = -v
111 void mxd_negeq_vec(mxds_vector *v);
113 // print one out
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);
131 // m = I
132 void mxd_identity_mat(mxds_matrix *m);
134 // dest = src
135 void mxd_copy_mat(mxds_matrix *dest,const mxds_matrix *src);
137 // dest = m * s
138 void mxd_scale_mat(mxds_matrix *dest,const mxds_matrix *m,double s);
139 // m *= s
140 void mxd_scaleeq_mat(mxds_matrix *m,double s);
142 // dest = m/s
143 void mxd_div_mat(mxds_matrix *dest,const mxds_matrix *m,double s);
144 // m /= s
145 void mxd_diveq_mat(mxds_matrix *m,double s);
147 // return |m|
148 double mxd_det_mat(const mxds_matrix *m);
150 // dest = m^t
151 void mxd_trans_mat(mxds_matrix *dest,const mxds_matrix *m);
152 // m = m^t
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);
157 // m = m^-1
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);
173 // dest = m1 x m2
174 void mxd_mul_mat(mxds_matrix *dest,const mxds_matrix *m1,const mxds_matrix *m2);
175 // m1 = m1 x m2
176 void mxd_muleq_mat(mxds_matrix *m1,const mxds_matrix *m2);
178 // dest = m1^t x m2
179 void mxd_tmul_mat(mxds_matrix *dest,const mxds_matrix *m1,const mxds_matrix *m2);
180 // m2 = m1^t x m2
181 void mxd_tmuleq_mat(const mxds_matrix *m1,mxds_matrix *m2);
183 // dest = m1 x m2^t
184 void mxd_mult_mat(mxds_matrix *dest,const mxds_matrix *m1,const mxds_matrix *m2);
187 // dest = m1 .x m2
188 void mxd_elmul_mat(mxds_matrix *dest,const mxds_matrix *m1,const mxds_matrix *m2);
189 // m1 .x= m2
190 void mxd_elmuleq_mat(mxds_matrix *m1,const mxds_matrix *m2);
192 // swap rows
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);
195 // swap cols
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);
199 // print one out
200 void mxd_prn_mat(const mxds_matrix *m);
202 // VECTOR ANGLE OPS
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);
211 // MATRIX ANGLE OPS
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
275 // system
276 // dest = M .* v
277 void mxd_mat_elmul_vec(mxds_matrix *dest,const mxds_matrix *m,const mxds_vector *v);
278 // M .*= v
279 void mxd_mat_elmuleq_vec(mxds_matrix *m,const mxds_vector *v);
281 // dest = v^t .* M
282 void mxd_mat_eltmul_vec(mxds_matrix *dest,const mxds_matrix *m,const mxds_vector *v);
283 // M .*= v^t
284 void mxd_mat_eltmuleq_vec(mxds_matrix *m,const mxds_vector *v);
286 // dest = M x 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);
293 // v x= M^t
294 void mxd_mat_tmuleq_vec(const mxds_matrix *m,mxds_vector *v);
296 // TRANSFORM OPS
298 // identity transform
299 void mxd_identity_trans(mxds_trans *t);
301 // copy transform
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
308 // dest = t1 * t2
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
313 // dest = t1^t * t2
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
318 // dest = t1 * t2^2
319 void mxd_mult_trans(mxds_trans *dest,const mxds_trans *t1,const mxds_trans *t2);
321 // multiply tform by vector
322 // dest = t * v
323 void mxd_trans_mul_vec(mxds_vector *dest,const mxds_trans *t,const mxds_vector *v);
325 // inverse multiply tform by vector
326 // dest = t^t * v
327 void mxd_trans_tmul_vec(mxds_vector *dest,const mxds_trans *t,const mxds_vector *v);
329 // print one out
330 void mxd_prn_trans(const mxds_trans *t);
333 #ifdef __cplusplus
335 #endif
337 #endif /* __MATRIXD_H */