OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WUNITSPHERECOORDINATES_H 00026 #define WUNITSPHERECOORDINATES_H 00027 00028 #include <cmath> 00029 #include <vector> 00030 00031 #include "../../common/math/linearAlgebra/WMatrixFixed.h" 00032 00033 /** 00034 * This class stores coordinates on the unit sphere. 00035 */ 00036 00037 template< typename T > class WUnitSphereCoordinates // NOLINT 00038 { 00039 // TODO(all): implement test 00040 // friend class WUnitSphereCoordinatesTest; 00041 public: 00042 /** 00043 * Default constructor. 00044 */ 00045 WUnitSphereCoordinates(); 00046 00047 /** 00048 * Constructor for unit sphere angles. 00049 * \param theta coordinate 00050 * \param phi coordinate 00051 */ 00052 WUnitSphereCoordinates( T theta, T phi ); 00053 00054 /** 00055 * Constructor for Euclidean coordinates. 00056 * \param vector Euclidean coordinates 00057 */ 00058 explicit WUnitSphereCoordinates( const WMatrixFixed< T, 3, 1 >& vector ); 00059 00060 /** 00061 * Destructor. 00062 */ 00063 virtual ~WUnitSphereCoordinates(); 00064 00065 /** 00066 * Return the theta angle. 00067 * 00068 * \return theta angle 00069 */ 00070 T getTheta() const; 00071 00072 /** 00073 * Return the phi angle. 00074 * 00075 * \return phi angle 00076 */ 00077 T getPhi() const; 00078 00079 /** 00080 * Set theta angle. 00081 * \param theta Value for theta. 00082 */ 00083 void setTheta( T theta ); 00084 00085 /** 00086 * Set phi angle. 00087 * \param phi Value for phi. 00088 */ 00089 void setPhi( T phi ); 00090 00091 /** 00092 * Returns the stored sphere coordinates as Euclidean coordinates. 00093 * 00094 * \return sphere coordinates in euclidean space 00095 */ 00096 WMatrixFixed< T, 3, 1 > getEuclidean() const; 00097 00098 /** 00099 * Returns the stored sphere coordinates as Euclidean coordinates. 00100 * 00101 * \param vector coordinates in euclidean space 00102 */ 00103 void setEuclidean( WMatrixFixed< T, 3, 1 > vector ); 00104 00105 protected: 00106 private: 00107 /** coordinate */ 00108 T m_theta; 00109 /** coordinate */ 00110 T m_phi; 00111 }; 00112 00113 template< typename T > 00114 WUnitSphereCoordinates< T >::WUnitSphereCoordinates() 00115 : m_theta( 0.0 ), 00116 m_phi( 0.0 ) 00117 { 00118 } 00119 00120 template< typename T > 00121 WUnitSphereCoordinates< T >::WUnitSphereCoordinates( T theta, T phi ) 00122 : m_theta( theta ), 00123 m_phi( phi ) 00124 { 00125 } 00126 00127 template< typename T > 00128 WUnitSphereCoordinates< T >::WUnitSphereCoordinates( const WMatrixFixed< T, 3, 1 >& vector ) 00129 { 00130 setEuclidean( vector ); 00131 } 00132 00133 template< typename T > 00134 WUnitSphereCoordinates< T >::~WUnitSphereCoordinates() 00135 { 00136 } 00137 00138 template< typename T > 00139 T WUnitSphereCoordinates< T >::getTheta() const 00140 { 00141 return m_theta; 00142 } 00143 00144 template< typename T > 00145 T WUnitSphereCoordinates< T >::getPhi() const 00146 { 00147 return m_phi; 00148 } 00149 00150 template< typename T > 00151 void WUnitSphereCoordinates< T >::setTheta( T theta ) 00152 { 00153 m_theta = theta; 00154 } 00155 00156 template< typename T > 00157 void WUnitSphereCoordinates< T >::setPhi( T phi ) 00158 { 00159 m_phi = phi; 00160 } 00161 00162 template< typename T > 00163 WMatrixFixed< T, 3, 1 > WUnitSphereCoordinates< T >::getEuclidean() const 00164 { 00165 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 ) ); 00166 } 00167 00168 template< typename T > 00169 void WUnitSphereCoordinates< T >::setEuclidean( WMatrixFixed< T, 3, 1 > vector ) 00170 { 00171 vector = normalize( vector ); 00172 // calculate angles 00173 m_theta = std::acos( vector[2] ); 00174 m_phi = std::atan2( vector[1], vector[0] ); 00175 } 00176 00177 #endif // WUNITSPHERECOORDINATES_H