]> Creatis software - creaRigidRegistration.git/blob - lib/PlanesOperations.cxx
ede64944a54ccef62562e99b7d94ad485f2453ad
[creaRigidRegistration.git] / lib / PlanesOperations.cxx
1
2 #include "PlanesOperations.h"
3
4 /********************************************************************************************
5 ** Start of data viewmanagerData
6 *********************************************************************************************/
7
8 PlanesOperations::PlanesOperations()
9 {       
10 }
11
12
13 PlanesOperations::~PlanesOperations()
14 {
15
16 }
17
18
19 double* PlanesOperations::getCrossProduct(double* vect0,double* vect1)
20 {
21         double* vectCross;
22         vectCross = new double[3];
23         vectCross[0] = vect0[1]*vect1[2]-(vect0[2]*vect1[1]);
24         vectCross[1] = -(vect0[0]*vect1[2]-(vect0[2]*vect1[0]));
25         vectCross[2] = vect0[0]*vect1[1]-(vect0[1]*vect1[0]);
26
27         return vectCross;
28 }
29
30 double PlanesOperations::getDotProduct(double* vect0,double* vect1)
31 {
32         double vectDot;
33         vectDot = vect0[0]*vect1[0] + vect0[1]*vect1[1] + vect0[2]*vect1[2];
34         
35         return vectDot;
36 }
37 /**
38 **      Returns the magnitud of the given vector
39 **/
40 double PlanesOperations::getMagnitud(double* vect)
41 {
42         double mag;
43
44         mag = sqrt(pow(vect[0],2) + pow(vect[1],2) + pow(vect[2],2));
45
46         return mag;
47 }
48 /**
49 **      returns the unitary vector of the given vector
50 **      u = 1/|vect| . vect
51 **/
52 double* PlanesOperations::getNormal(double* vect)
53 {
54
55         double* vectnorm;
56         double mag = getMagnitud(vect);
57
58         vectnorm = new double[3];
59         
60         if(mag!=0){
61                 vectnorm[0] = vect[0]/mag;
62                 vectnorm[1] = vect[1]/mag;
63                 vectnorm[2] = vect[2]/mag;
64         }else{
65                 vectnorm[0] = 0;
66                 vectnorm[1] = 0;
67                 vectnorm[2] = 0;
68         }
69         return vectnorm;
70 }
71
72 double* PlanesOperations::makeVector(double podouble0[3], double podouble1[3])
73 {
74         double *vect;
75         vect = new double[3];
76
77         vect[0]= podouble1[0]-podouble0[0];
78         vect[1]= podouble1[1]-podouble0[1];
79         vect[2]= podouble1[2]-podouble0[2];
80
81         return vect;
82 }
83