dbf-halloween2015

view 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 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 }