FSpherical.hpp 1.36 KB
 berenger-bramas committed Jan 24, 2012 1 2 3 4 ``````#ifndef FSPHERICAL_HPP #define FSPHERICAL_HPP #include "FGlobal.hpp" `````` berenger-bramas committed Feb 06, 2012 5 ``````#include "FMath.hpp" `````` berenger-bramas committed Jan 24, 2012 6 7 8 9 10 11 ``````#include "F3DPosition.hpp" /** This class is a Spherical position * This class is currently in its minimum version */ class FSpherical { `````` berenger-bramas committed Jan 27, 2012 12 13 14 15 16 `````` // The attributes of a sphere FReal r; FReal cosTheta; FReal sinTheta; FReal phi; `````` berenger-bramas committed Jan 24, 2012 17 18 `````` public: `````` berenger-bramas committed Jan 27, 2012 19 `````` /** From now, we just need a constructor based on a 3D position */ `````` berenger-bramas committed Jan 24, 2012 20 21 22 23 `````` explicit FSpherical(const F3DPosition& inVector){ const FReal x2y2 = (inVector.getX() * inVector.getX()) + (inVector.getY() * inVector.getY()); this->r = FMath::Sqrt( x2y2 + (inVector.getZ() * inVector.getZ())); this->phi = FMath::Atan2(inVector.getY(),inVector.getX()); `````` berenger-bramas committed Feb 06, 2012 24 25 26 27 28 29 30 31 `````` if( r < FMath::Epsilon ){ // if r == 0 we cannot divide! this->cosTheta = FReal(1); this->sinTheta = FReal(1); } else { this->cosTheta = inVector.getZ() / r; this->sinTheta = FMath::Sqrt(x2y2) / r; } `````` berenger-bramas committed Jan 24, 2012 32 33 `````` } `````` berenger-bramas committed Jan 27, 2012 34 `````` /** Get the rayon */ `````` berenger-bramas committed Jan 24, 2012 35 36 37 38 `````` FReal getR() const{ return r; } `````` berenger-bramas committed Jan 27, 2012 39 `````` /** Get the cos theta = z / r */ `````` berenger-bramas committed Jan 24, 2012 40 41 42 43 `````` FReal getCosTheta() const{ return cosTheta; } `````` berenger-bramas committed Jan 27, 2012 44 `````` /** Get the sin theta = sqrt(x2y2) / r */ `````` berenger-bramas committed Jan 24, 2012 45 46 47 48 `````` FReal getSinTheta() const{ return sinTheta; } `````` berenger-bramas committed Jan 27, 2012 49 `````` /** Get the phi = atan2(y,x) */ `````` berenger-bramas committed Jan 24, 2012 50 51 52 53 54 55 `````` FReal getPhi() const{ return phi; } }; #endif // FSPHERICAL_HPP``````