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