1 #ifndef vm_v3math_h_INCLUDED
2 #define vm_v3math_h_INCLUDED
39 #include <vm_math/vm_vmath.h>
74 enum ENelts_ { ENelts = 3 };
99 inline static void set( T_fp v[], T_fp x, T_fp y, T_fp z );
107 inline static void set( T_fp v[], T_fp x );
122 inline static T_fp
unitize( T_fp v[] );
132 inline static T_fp
unitize( T_fp vu[], T_fp
const vi[] );
149 inline static int is_unit_vector( T_fp
const v[], T_fp
const tol );
161 inline static int are_orthogonal( T_fp
const v[], T_fp
const other[],
192 inline static T_fp
dot( T_fp
const v1[], T_fp
const v2[] );
203 inline static void cross( T_fp prod[],
204 T_fp
const v1[], T_fp
const v2[] );
220 inline static std::ostream&
221 print_on( std::ostream& os, T_fp
const v[],
222 char const prefix[] =
"",
char const postfix[] =
"" );
234 char const prefix[] =
"",
char const postfix[] =
"" );
253 template <
class T_fp>
255 set( T_fp v[], T_fp x, T_fp y, T_fp z )
256 { v[0] = x; v[1] = y; v[2] = z; }
258 template <
class T_fp>
263 template <
class T_fp>
265 dot( T_fp
const v1[], T_fp
const v2[] )
267 return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
270 template <
class T_fp>
273 T_fp
const v1[], T_fp
const v2[] )
275 result[0] = v1[1] * v2[2] - v1[2] * v2[1];
276 result[1] = v1[2] * v2[0] - v1[0] * v2[2];
277 result[2] = v1[0] * v2[1] - v1[1] * v2[0];
280 template <
class T_fp>
284 T_fp size = sqrt( dot( v, v ) );
294 template <
class T_fp>
302 template <
class T_fp>
306 return !( (fabs(sqrt(dot(v, v))-1.0) > tol ) ? 1 : 0 );
309 template <
class T_fp>
315 return !( (fabs(dot(v, other)) > tol ) ? 1 : 0 );
318 template <
class T_fp>
324 return is_unit_vector(v,tol) &&
325 is_unit_vector(other,tol) &&
326 are_orthogonal(v,other,tol);
329 template <
class T_fp>
332 char const prefix[],
char const postfix[] )
333 {
if ( std::strlen(prefix) ) { os << prefix; }
334 os << v[0] <<
" " << v[1] <<
" " << v[2];
335 if ( std::strlen(postfix) ) { os << postfix; }
338 template <
class T_fp>
341 char const prefix[],
char const postfix[] )
342 {
if ( std::strlen(prefix) ) { std::fprintf(of,
"%s", prefix); }
343 std::fprintf(of,
"%.18e %.18e %.18e\n", v[0], v[1], v[2]);
344 if ( std::strlen(postfix) ) { std::fprintf(of,
"%s", postfix); } }