Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / applications / utilities / surface / surfaceCoarsen / bunnylod / vector.h
blob26dd9bbe71cb8402b35f7f51458491475ab9126d
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){
51 v=normalize(v);
52 r=float(cos(t/2.0));
53 v=v*float(sin(t/2.0));
54 x=v.x;
55 y=v.y;
56 z=v.z;
58 Quaternion(float _r,float _x,float _y,float _z){r=_r;x=_x;y=_y;z=_z;};
59 float angle(){return float(acos(r)*2.0);}
60 Vector axis(){Vector a(x,y,z); return a*float(1/sin(angle()/2.0));}
61 Vector xdir(){
62 return Vector(1-2*(y*y+z*z), 2*(x*y+r*z), 2*(x*z-r*y));
64 Vector ydir(){
65 return Vector( 2*(x*y-r*z),1-2*(x*x+z*z), 2*(y*z+r*x));
67 Vector zdir(){
68 return Vector( 2*(x*z+r*y), 2*(y*z-r*x),1-2*(x*x+y*y));
70 matrix getmatrix(){return matrix(xdir(),ydir(),zdir());}
71 //operator matrix(){return getmatrix();}
73 Quaternion operator-(Quaternion q);
74 Quaternion operator*(Quaternion a,Quaternion b);
75 Vector operator*(Quaternion q,Vector v);
76 Vector operator*(Vector v,Quaternion q);
77 Quaternion slerp(Quaternion a,Quaternion b,float interp);
79 #endif