Fraxinus  17.12-rc2
An IGT application
helpers.hpp
Go to the documentation of this file.
1 #ifndef HELPERS_HPP
2 #define HELPERS_HPP
3 #include <cmath>
9 template <typename T> int sgn(T val) {
10  return (T(0) < val) - (val < T(0));
11 }
12 
13 
19 template <typename T> T length3d(T const a[3])
20 {
21  T ret = 0.0;
22  for(int i = 0; i < 3; i++)
23  {
24  ret += a[i]*a[i];
25  }
26  return sqrt(ret);
27 }
28 
34 template <typename T> void normalize3d(T normalized[3], T const toNormalize[3] )
35 {
36  T normalization = length3d(toNormalize);
37  for(int i = 0; i < 3; i++)
38  {
39  normalized[i] = toNormalize[i]/normalization;
40  }
41 }
48 template <typename T> T innerProduct(T const one[3], T const two[3])
49 {
50  T sum = 0;
51  for(int i = 0; i < 3; i++)
52  {
53  sum += one[i]*two[i];
54  }
55  return sum;
56 }
57 
58 #define radToDeg(x) (180.0*x/M_PI)
59 #define degToRad(x) (M_PI*x/180.0)
60 
61 #endif
void normalize3d(T normalized[3], T const toNormalize[3])
Definition: helpers.hpp:34
int sgn(T val)
Definition: helpers.hpp:9
T length3d(T const a[3])
Definition: helpers.hpp:19
T innerProduct(T const one[3], T const two[3])
Definition: helpers.hpp:48