dbf-halloween2015

diff libs/vmath/sphvec.cc @ 1:c3f5c32cb210

barfed all the libraries in the source tree to make porting easier
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 01 Nov 2015 00:36:56 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/vmath/sphvec.cc	Sun Nov 01 00:36:56 2015 +0200
     1.3 @@ -0,0 +1,27 @@
     1.4 +#include "sphvec.h"
     1.5 +#include "vector.h"
     1.6 +
     1.7 +/* theta: 0 <= theta <= 2pi, the angle around Y axis.
     1.8 + * phi: 0 <= phi <= pi, the angle from Y axis.
     1.9 + * r: radius.
    1.10 + */
    1.11 +SphVector::SphVector(scalar_t theta, scalar_t phi, scalar_t r) {
    1.12 +	this->theta = theta;
    1.13 +	this->phi = phi;
    1.14 +	this->r = r;
    1.15 +}
    1.16 +
    1.17 +/* Constructs a spherical coordinate vector from a cartesian vector */
    1.18 +SphVector::SphVector(const Vector3 &cvec) {
    1.19 +	*this = cvec;
    1.20 +}
    1.21 +
    1.22 +/* Assignment operator that converts cartesian to spherical coords */
    1.23 +SphVector &SphVector::operator =(const Vector3 &cvec) {
    1.24 +	r = cvec.length();
    1.25 +	//theta = atan2(cvec.y, cvec.x);
    1.26 +	theta = atan2(cvec.z, cvec.x);
    1.27 +	//phi = acos(cvec.z / r);
    1.28 +	phi = acos(cvec.y / r);
    1.29 +	return *this;
    1.30 +}