versor  3.0
C++11 library for Geometric algebra
vsr_coord.h
1 //
2 // vsr_coord.h
3 // Versor
4 // COORDINATE MAPPINGS
5 // Created by Pablo Colapinto on 11/26/12.
6 // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7 //
8 
9 #ifndef Versor_vsr_coord_h
10 #define Versor_vsr_coord_h
11 
12 #include "space/vsr_cga3D_op.h"
13 
14 //#include <iostream>
15 
16 
17 using namespace std;
18 
19 namespace vsr { namespace cga {
20 
21  namespace Coord{
22 
23  struct Sph{
24  Sph( double t, double p, double r) : theta(t), phi(p), rad(r) {}
25  double theta, phi, rad;
26 
27  void print() { printf("az: %f\telev: %f\tdist: %f", theta, phi, rad); }
28  // friend ostream& operator << (ostream& os, const Sph& s);
29  };
30 
31  // inline ostream& operator << (ostream& os, const Sph& s){
32  // os << "az: " << s.theta << "\telev: " << s.phi << "\tdist: " << s.rad;
33  // return os;
34  // }
35 
36  inline Vec sph2vec(double theta, double phi){
37  Rot r = Gen::rot(theta/2.0, phi/2.0);
38  return Vec::x.sp(r);
39  }
40 
41  inline Sph vec2sph(const Vec& tv){
42  double r = tv.norm();
43  return Sph( atan2(tv[2],tv[0]) , acos(-tv[1]/r) - PIOVERTWO, r);
44  }
45 
46  //to degree format with 0 straight ahead
47  inline Sph sph2deg( const Sph& cs ){
48  double a = ( 180. * ( ( cs.theta / PI ) + 1. ) ) - 90.;
49  if (a < 0 ) a = 360 + a;
50  double e = 90. * cs.phi / PIOVERTWO;
51  double r = cs.rad;
52  return Sph( a, e, r );
53  }
54 
55  template<typename T>
56  inline Sph vec2deg( const T& v ){
57  return sph2deg( vec2sph(v) );
58  }
59  }
60 } }//vsr::cga::
61 
62 
63 
64 
65 
66 
67 #endif
Common Operations Specific to CGA3D.
Generic Geometric Number Types (templated on an algebra and a basis )
Definition: vsr_algebra.h:69
the versor library namespace
Definition: vsr_algebra.h:29
Definition: vsr_coord.h:23
NSph< 5 > Sph
Sphere
Definition: vsr_cga3D_types.h:75