initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / surface / surfaceCoarsen / bunnylod / vector.h
blob22703d8bf2c639e912201c0cd3de18bd6f5198ee
1 //
2 // This module contains a bunch of well understood functions
3 // I apologise if the conventions used here are slightly
4 // different than what you are used to.
5 //
7 #ifndef GENERIC_VECTOR_H
8 #define GENERIC_VECTOR_H
10 #include <stdio.h>
11 #include <math.h>
14 class Vector {
15 public:
16 float x,y,z;
17 Vector(float _x=0.0,float _y=0.0,float _z=0.0){x=_x;y=_y;z=_z;};
18 operator float *() { return &x;};
21 float magnitude(Vector v);
22 Vector normalize(Vector v);
24 Vector operator+(Vector v1,Vector v2);
25 Vector operator-(Vector v);
26 Vector operator-(Vector v1,Vector v2);
27 Vector operator*(Vector v1,float s) ;
28 Vector operator*(float s,Vector v1) ;
29 Vector operator/(Vector v1,float s) ;
30 float operator^(Vector v1,Vector v2); // DOT product
31 Vector operator*(Vector v1,Vector v2); // CROSS product
32 Vector planelineintersection(Vector n,float d,Vector p1,Vector p2);
34 class matrix{
35 public:
36 Vector x,y,z;
37 matrix(){x=Vector(1.0f,0.0f,0.0f);
38 y=Vector(0.0f,1.0f,0.0f);
39 z=Vector(0.0f,0.0f,1.0f);};
40 matrix(Vector _x,Vector _y,Vector _z){x=_x;y=_y;z=_z;};
42 matrix transpose(matrix m);
43 Vector operator*(matrix m,Vector v);
44 matrix operator*(matrix m1,matrix m2);
46 class Quaternion{
47 public:
48 float r,x,y,z;
49 Quaternion(){x=y=z=0.0f;r=1.0f;};
50 Quaternion(Vector v,float t){v=normalize(v);r=float(cos(t/2.0));v=v*float(sin(t/2.0));x=v.x;y=v.y;z=v.z;};
51 Quaternion(float _r,float _x,float _y,float _z){r=_r;x=_x;y=_y;z=_z;};
52 float angle(){return float(acos(r)*2.0);}
53 Vector axis(){Vector a(x,y,z); return a*float(1/sin(angle()/2.0));}
54 Vector xdir(){return Vector(1-2*(y*y+z*z), 2*(x*y+r*z), 2*(x*z-r*y));}
55 Vector ydir(){return Vector( 2*(x*y-r*z),1-2*(x*x+z*z), 2*(y*z+r*x));}
56 Vector zdir(){return Vector( 2*(x*z+r*y), 2*(y*z-r*x),1-2*(x*x+y*y));}
57 matrix getmatrix(){return matrix(xdir(),ydir(),zdir());}
58 //operator matrix(){return getmatrix();}
60 Quaternion operator-(Quaternion q);
61 Quaternion operator*(Quaternion a,Quaternion b);
62 Vector operator*(Quaternion q,Vector v);
63 Vector operator*(Vector v,Quaternion q);
64 Quaternion slerp(Quaternion a,Quaternion b,float interp);
66 #endif