2 #include "PlanesOperations.h"
4 /********************************************************************************************
5 ** Start of data viewmanagerData
6 *********************************************************************************************/
10 PlanesOperations::PlanesOperations()
15 PlanesOperations::~PlanesOperations()
21 double* PlanesOperations::getCrossProduct(double* vect0,double* vect1)
24 vectCross = new double[3];
25 vectCross[0] = vect0[1]*vect1[2]-(vect0[2]*vect1[1]);
26 vectCross[1] = -(vect0[0]*vect1[2]-(vect0[2]*vect1[0]));
27 vectCross[2] = vect0[0]*vect1[1]-(vect0[1]*vect1[0]);
32 ** Returns the magnitud of the given vector
34 double PlanesOperations::getMagnitud(double* vect)
38 mag = sqrt(pow(vect[0],2) + pow(vect[1],2) + pow(vect[2],2));
40 //std::cout<<"mag "<<mag <<std::endl;
45 ** returns the unitary vector of the given vector
46 ** u = 1/|vect| . vect
48 double* PlanesOperations::getNormal(double* vect)
52 double mag = getMagnitud(vect);
54 vectnorm = new double[3];
57 vectnorm[0] = vect[0]/mag;
58 vectnorm[1] = vect[1]/mag;
59 vectnorm[2] = vect[2]/mag;
68 double* PlanesOperations::makeVector(double *podouble0, double *podouble1)
73 vect[0]= podouble1[0]-podouble0[0];
74 vect[1]= podouble1[1]-podouble0[1];
75 vect[2]= podouble1[2]-podouble0[2];
80 void PlanesOperations::getCrossProduct(double* vect0,double* vect1, double* vectres){
81 vectres[0] = vect0[1]*vect1[2]-(vect0[2]*vect1[1]);
82 vectres[1] = -(vect0[0]*vect1[2]-(vect0[2]*vect1[0]));
83 vectres[2] = vect0[0]*vect1[1]-(vect0[1]*vect1[0]);
86 void PlanesOperations::getNormal(double* vect, double* vectnorm){
88 double mag = getMagnitud(vect);
91 vectnorm[0] = vect[0]/mag;
92 vectnorm[1] = vect[1]/mag;
93 vectnorm[2] = vect[2]/mag;
101 void PlanesOperations::makeVector(double* podouble0, double* podouble1, double* vectres){
102 vectres[0] = podouble1[0] - podouble0[0];
103 vectres[1] = podouble1[1] - podouble0[1];
104 vectres[2] = podouble1[2] - podouble0[2];
107 double PlanesOperations::getDotProduct(double* vect0,double* vect1){
108 return vect0[0]*vect1[0] + vect0[1]*vect1[1] + vect0[2]*vect1[2];
111 void PlanesOperations::addVectors(double* vect0, double* vect1, double*vectres){
113 vectres[0]= vect0[0] + vect1[0];
114 vectres[1]= vect0[1] + vect1[1];
115 vectres[2]= vect0[2] + vect1[2];
118 void PlanesOperations::scalarVector(double* vect0, double scalar, double*vectres){
120 vectres[0]= vect0[0]*scalar;
121 vectres[1]= vect0[1]*scalar;
122 vectres[2]= vect0[2]*scalar;
125 vector<double> PlanesOperations::getCrossProduct(vector<double> vect0,vector<double> vect1){
127 vector<double> vectCross;
129 for(unsigned i = 0; i < vect0.size(); i++){
131 unsigned ii = (i + 1 == vect0.size())? 0: i + 1;
132 unsigned iii = (ii + 1 == vect0.size())? 0: ii + 1;
134 vectCross.push_back( vect0[ii]*vect1[iii]- vect0[iii]*vect1[ii] );
140 double PlanesOperations::getDotProduct(vector<double> vect0,vector<double> vect1){
144 for(unsigned i = 0; i < vect0.size(); i++) sum += vect0[i]*vect1[i];
148 vector<double> PlanesOperations::getNormal(vector<double> vect){
149 vector<double> vectnorm;
150 double mag = getMagnitud(vect);
152 for(unsigned i = 0; i < vect.size(); i++){
155 vectnorm.push_back(vect[i]/mag);
157 vectnorm.push_back(0);
162 double PlanesOperations::getMagnitud(vector<double> vect){
165 for(unsigned i = 0; i < vect.size(); i++) mag += pow(vect[i], 2);
169 //std::cout<<"mag "<<mag <<std::endl;
173 vector<double> PlanesOperations::makeVector(vector<double> podouble0, vector<double> podouble1){
175 vector<double> vector;
177 for(unsigned i = 0; i < podouble0.size(); i++){
178 vector.push_back(podouble1[i] - podouble0[i]);
184 * Adds to vectors, the result is in vectres;
185 *@param double* vect0, the first vector
186 *@param double* vect1, the second vector
187 *@param double* vectres, the resulting vector
189 vector<double> PlanesOperations::addVectors(vector<double> vect0, vector<double> vect1){
190 vector<double> vectres;
191 for(unsigned i = 0; i < vect0.size(); i++){
192 vectres.push_back(vect0[i] + vect1[i]);
198 * multiply a vector with a given scalar
199 *@param double* vect0, the vector
200 *@param double scalar, the scalar value
201 *@param double* vectres, the resulting vector
203 vector<double> PlanesOperations::scalarVector(vector<double> vect0, double scalar){
204 vector<double> vectres;
205 for(unsigned i = 0; i < vect0.size(); i++){
206 vectres.push_back(vect0[i]*scalar);