OpenWalnut  1.5.0dev
WUnitSphereCoordinates.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WUNITSPHERECOORDINATES_H
26 #define WUNITSPHERECOORDINATES_H
27 
28 #include <cmath>
29 #include <vector>
30 
31 #include "../../common/math/linearAlgebra/WMatrixFixed.h"
32 
33 /**
34  * This class stores coordinates on the unit sphere.
35  */
36 
37 template< typename T > class WUnitSphereCoordinates // NOLINT
38 {
39 // TODO(all): implement test
40 // friend class WUnitSphereCoordinatesTest;
41 public:
42  /**
43  * Default constructor.
44  */
46 
47  /**
48  * Constructor for unit sphere angles.
49  * \param theta coordinate
50  * \param phi coordinate
51  */
52  WUnitSphereCoordinates( T theta, T phi );
53 
54  /**
55  * Constructor for Euclidean coordinates.
56  * \param vector Euclidean coordinates
57  */
58  explicit WUnitSphereCoordinates( const WMatrixFixed< T, 3, 1 >& vector );
59 
60  /**
61  * Destructor.
62  */
63  virtual ~WUnitSphereCoordinates();
64 
65  /**
66  * Return the theta angle.
67  *
68  * \return theta angle
69  */
70  T getTheta() const;
71 
72  /**
73  * Return the phi angle.
74  *
75  * \return phi angle
76  */
77  T getPhi() const;
78 
79  /**
80  * Set theta angle.
81  * \param theta Value for theta.
82  */
83  void setTheta( T theta );
84 
85  /**
86  * Set phi angle.
87  * \param phi Value for phi.
88  */
89  void setPhi( T phi );
90 
91  /**
92  * Returns the stored sphere coordinates as Euclidean coordinates.
93  *
94  * \return sphere coordinates in euclidean space
95  */
97 
98  /**
99  * Returns the stored sphere coordinates as Euclidean coordinates.
100  *
101  * \param vector coordinates in euclidean space
102  */
103  void setEuclidean( WMatrixFixed< T, 3, 1 > vector );
104 
105 protected:
106 private:
107  /** coordinate */
109  /** coordinate */
110  T m_phi;
111 };
112 
113 template< typename T >
115  : m_theta( 0.0 ),
116  m_phi( 0.0 )
117 {
118 }
119 
120 template< typename T >
122  : m_theta( theta ),
123  m_phi( phi )
124 {
125 }
126 
127 template< typename T >
129 {
130  setEuclidean( vector );
131 }
132 
133 template< typename T >
135 {
136 }
137 
138 template< typename T >
140 {
141  return m_theta;
142 }
143 
144 template< typename T >
146 {
147  return m_phi;
148 }
149 
150 template< typename T >
152 {
153  m_theta = theta;
154 }
155 
156 template< typename T >
158 {
159  m_phi = phi;
160 }
161 
162 template< typename T >
164 {
165  return WMatrixFixed< T, 3, 1 >( std::sin( m_theta )*std::cos( m_phi ), std::sin( m_theta )*std::sin( m_phi ), std::cos( m_theta ) );
166 }
167 
168 template< typename T >
170 {
171  vector = normalize( vector );
172  // calculate angles
173  m_theta = std::acos( vector[2] );
174  m_phi = std::atan2( vector[1], vector[0] );
175 }
176 
177 #endif // WUNITSPHERECOORDINATES_H
This class stores coordinates on the unit sphere.
void setPhi(T phi)
Set phi angle.
T getTheta() const
Return the theta angle.
void setEuclidean(WMatrixFixed< T, 3, 1 > vector)
Returns the stored sphere coordinates as Euclidean coordinates.
void setTheta(T theta)
Set theta angle.
WUnitSphereCoordinates()
Default constructor.
virtual ~WUnitSphereCoordinates()
Destructor.
T getPhi() const
Return the phi angle.
WMatrixFixed< T, 3, 1 > getEuclidean() const
Returns the stored sphere coordinates as Euclidean coordinates.