1 #include "vectorFunctions.h"
5 vectorFunctions::vectorFunctions()
9 vectorFunctions::~vectorFunctions()
13 //---------------------------------------------------------------
14 //Copy Vector1 in Vector2 (double)
15 void vectorFunctions::copyVector(std::vector<double>*Vector1,std::vector<double>*Vector2)
17 int size = Vector1->size();
24 Vector2->push_back( (*Vector1)[i] );
28 //---------------------------------------------------------------
29 //Copy Vector1 in Vector2 (int)
30 void vectorFunctions::copyintVector(std::vector<int>*Vector1,std::vector<int>*Vector2)
32 int size = Vector1->size();
39 Vector2->push_back( (*Vector1)[i] );
43 //------------------------------------------------------------------------------------------------------------------------------------------
44 //Print 2 vectors of the same size
45 void vectorFunctions::printVector(std::vector<double>*Vector1,std::vector<double>*Vector2)
48 if( Vector1->size() == Vector2->size() )
50 for(i=0; i<Vector1->size(); i++)
52 printf("\n v1(%d) = %f, v2(%d) = %f",i,(*Vector1)[i],i,(*Vector2)[i]);
56 //------------------------------------------------------------------------------------------------------------------------------------------
57 //Returns the average value of the vector
58 double vectorFunctions::promVector(std::vector<double>*Vector1, bool OnNormal)
62 std::vector<double> tempv;
63 int size = Vector1->size();
70 suma = suma + (*Vector1)[i];
72 return prom = suma/Vector1->size();
76 copyVector(Vector1,&tempv);
79 pos = maxVector(Vector1,&maxval);
82 tempv.push_back((*Vector1)[i]/maxval);
85 for(i=0; i<tempv.size(); i++)
87 suma = suma + tempv[i];
89 return prom = suma/tempv.size();
94 //------------------------------------------------------------------------------------------------------------------------------------------
95 //Returns the maximum value of the vector
96 int vectorFunctions::maxVector(std::vector<double>*Vector1,double *val)
100 if(Vector1->size() != 0)
102 for(i=0; i<Vector1->size(); i++)
104 if( (*Vector1)[i]>max )
115 //------------------------------------------------------------------------------------------------------------------------------------------
116 //Returns the minimum value of the vector
117 int vectorFunctions::minVector(std::vector<double>*Vector1,double *val)
121 if(Vector1->size() != 0)
123 for(i=0; i<Vector1->size(); i++)
125 if( (*Vector1)[i]<min )
136 //------------------------------------------------------------------------------------------------------------------------------------------
137 //Find the minimal distance between an input point and an input lists of points
138 int vectorFunctions::nearPoint(std::vector<double>*VectorX, std::vector<double>*VectorY, double px, double py)
141 double min = 10000, dist;
142 if(VectorX->size() != 0)
144 for(i=0; i<VectorX->size(); i++)
146 dist = sqrt(pow(px-(*VectorX)[i],2) + pow(py-(*VectorY)[i],2));
157 //------------------------------------------------------------------------------------------------------------------------------------------
158 //Returns the position of the point in the lsts. (Aprox. + or - 1).
159 int vectorFunctions::findPointInLst(std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ,
160 double x, double y, double z)
164 if(vecX->size() != 0)
166 for(i=0; i<vecX->size(); i++)
168 if( ((*vecX)[i]-apr <= x)&&(x <=(*vecX)[i]+apr)&&((*vecY)[i]-apr <= y)&&(y <=(*vecY)[i]+apr)&&((*vecZ)[i]-apr <= z)&&(z <=(*vecZ)[i]+apr) )