]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/Math.hpp
latest updates from JSBSim
[flightgear.git] / src / FDM / YASim / Math.hpp
1 #ifndef _MATH_HPP
2 #define _MATH_HPP
3
4 namespace yasim {
5
6 class Math
7 {
8 public:
9     // Dumb utilities
10     static float clamp(float val, float min, float max);
11
12     // Simple wrappers around library routines
13     static float abs(float f);
14     static float sqrt(float f);
15     static float ceil(float f);
16     static float sin(float f);
17     static float cos(float f);
18     static float tan(float f);
19     static float atan(float f);
20     static float atan2(float y, float x);
21     static float asin(float f);
22     static float acos(float f);
23     static float exp(float f);
24     static float sqr(float f) {return f*f;}
25
26     // Takes two args and runs afoul of the Koenig rules.
27     static float pow(double base, double exp);
28
29     // double variants of the above
30     static double abs(double f);
31     static double sqrt(double f);
32     static double ceil(double f);
33     static double sin(double f);
34     static double cos(double f);
35     static double tan(double f);
36     static double atan2(double y, double x);
37     static double floor(double x);
38
39     // Some 3D vector stuff.  In all cases, it is permissible for the
40     // "out" vector to be the same as one of the inputs.
41     static void  set3(float* v, float* out);
42     static float dot3(float* a, float* b);
43     static void  cross3(float* a, float* b, float* out);
44     static void  mul3(float scalar, float* v, float* out);
45     static void  add3(float* a, float* b, float* out);
46     static void  sub3(float* a, float* b, float* out);
47     static float mag3(float* v);
48     static void  unit3(float* v, float* out);
49
50     // Matrix array convention: 0 1 2
51     //                          3 4 5
52     //                          6 7 8
53
54     // Multiply two matrices
55     static void mmul33(float* a, float* b, float* out);
56
57     // Multiply by vector
58     static void vmul33(float* m, float* v, float* out);
59
60     // Multiply the vector by the matrix transpose.  Or pre-multiply the
61     // matrix by v as a row vector.  Same thing.
62     static void tmul33(float* m, float* v, float* out);
63
64     // Invert matrix
65     static void invert33(float* m, float* out);
66
67     // Transpose matrix (for an orthonormal orientation matrix, this
68     // is the same as the inverse).
69     static void trans33(float* m, float* out);
70
71     // Generates an orthonormal basis:
72     //   xOut becomes the unit vector in the direction of x
73     //   yOut is perpendicular to xOut in the x/y plane
74     //   zOut becomes the unit vector: (xOut cross yOut)
75     static void ortho33(float* x, float* y,
76                         float* xOut, float* yOut, float* zOut);
77 };
78
79 }; // namespace yasim
80 #endif // _MATH_HPP