FSpherical.hpp 1.36 KB
Newer Older
berenger-bramas's avatar
berenger-bramas committed
1 2 3 4
#ifndef FSPHERICAL_HPP
#define FSPHERICAL_HPP

#include "FGlobal.hpp"
5
#include "FMath.hpp"
berenger-bramas's avatar
berenger-bramas committed
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 {
12 13 14 15 16
    // The attributes of a sphere
    FReal r;
    FReal cosTheta;
    FReal sinTheta;
    FReal phi;
berenger-bramas's avatar
berenger-bramas committed
17 18

public:
19
    /** From now, we just need a constructor based on a 3D position */
berenger-bramas's avatar
berenger-bramas committed
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());
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's avatar
berenger-bramas committed
32 33
    }

34
    /** Get the rayon */
berenger-bramas's avatar
berenger-bramas committed
35 36 37 38
    FReal getR() const{
        return r;
    }

39
    /** Get the cos theta = z / r */
berenger-bramas's avatar
berenger-bramas committed
40 41 42 43
    FReal getCosTheta() const{
        return cosTheta;
    }

44
    /** Get the sin theta = sqrt(x2y2) / r */
berenger-bramas's avatar
berenger-bramas committed
45 46 47 48
    FReal getSinTheta() const{
        return sinTheta;
    }

49
    /** Get the phi = atan2(y,x) */
berenger-bramas's avatar
berenger-bramas committed
50 51 52 53 54 55
    FReal getPhi() const{
        return phi;
    }
};

#endif // FSPHERICAL_HPP