float MyVector::distance(MyVector theOtherVector){ return pow( pow(this->getX()-theOtherVector.getX(),int(2))+ pow(this->getY()-theOtherVector.getY(),int(2))+ pow(this->getZ()-theOtherVector.getZ(),int(2)) , (float) 0.5); }
// This account for the orientation of (i,j) vectors (computer graphics window basis orientation) MyVector <float> Util::fromCartesianToPolar(MyVector <float> origin, MyVector <float> v) { float x = v.getX(); float y = v.getY(); float ox = origin.getX(); float oy = origin.getY(); float a; float r = std::sqrt((x-ox)*(x-ox)+(y-oy)*(y-oy)); if(r == 0.0f) return MyVector <float> (0.0f, 0.0f); if(y - oy > 0.0f) a = 2 * M_PI - std::acos((x - ox)/r); else a = std::acos((x - ox)/r); return MyVector <float> (r, a); }
float Util::norm(MyVector <float> v1, MyVector <float> v2) { return norm(v1.getX(), v1.getY(), v2.getX(), v2.getY()); }
// no need for origin but here to remind that this will give X and Y offset to the point from // the same center used as polar origin // <!> have to make it consistent with (i,j) orientation (computer graphics window basis orientation) <!> MyVector <float> Util::fromPolarToCartesian(MyVector <float> origin, MyVector <float> v) { return MyVector <float> (v.getX() * std::cos(v.getY()), v.getX() * std::sin(v.getY())); }