goat3d
annotate libs/vmath/sphvec.cc @ 51:fa5c52ea9d59
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 17 Jan 2014 18:16:09 +0200 |
parents | |
children |
rev | line source |
---|---|
nuclear@27 | 1 #include "sphvec.h" |
nuclear@27 | 2 #include "vector.h" |
nuclear@27 | 3 |
nuclear@27 | 4 /* theta: 0 <= theta <= 2pi, the angle around Y axis. |
nuclear@27 | 5 * phi: 0 <= phi <= pi, the angle from Y axis. |
nuclear@27 | 6 * r: radius. |
nuclear@27 | 7 */ |
nuclear@27 | 8 SphVector::SphVector(scalar_t theta, scalar_t phi, scalar_t r) { |
nuclear@27 | 9 this->theta = theta; |
nuclear@27 | 10 this->phi = phi; |
nuclear@27 | 11 this->r = r; |
nuclear@27 | 12 } |
nuclear@27 | 13 |
nuclear@27 | 14 /* Constructs a spherical coordinate vector from a cartesian vector */ |
nuclear@27 | 15 SphVector::SphVector(const Vector3 &cvec) { |
nuclear@27 | 16 *this = cvec; |
nuclear@27 | 17 } |
nuclear@27 | 18 |
nuclear@27 | 19 /* Assignment operator that converts cartesian to spherical coords */ |
nuclear@27 | 20 SphVector &SphVector::operator =(const Vector3 &cvec) { |
nuclear@27 | 21 r = cvec.length(); |
nuclear@27 | 22 //theta = atan2(cvec.y, cvec.x); |
nuclear@27 | 23 theta = atan2(cvec.z, cvec.x); |
nuclear@27 | 24 //phi = acos(cvec.z / r); |
nuclear@27 | 25 phi = acos(cvec.y / r); |
nuclear@27 | 26 return *this; |
nuclear@27 | 27 } |