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