00001 /* 00002 * Copyright (C) 2003-2009 Olivier Boudeville 00003 * 00004 * This file is part of the Ceylan library. 00005 * 00006 * The Ceylan library is free software: you can redistribute it and/or modify 00007 * it under the terms of either the GNU Lesser General Public License or 00008 * the GNU General Public License, as they are published by the Free Software 00009 * Foundation, either version 3 of these Licenses, or (at your option) 00010 * any later version. 00011 * 00012 * The Ceylan library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License and the GNU General Public License 00016 * for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License and the GNU General Public License along with the Ceylan library. 00020 * If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 * Author: Olivier Boudeville (olivier.boudeville@esperide.com) 00023 * 00024 */ 00025 00026 00027 #include "CeylanEndomorphism.h" 00028 00029 00030 #include "CeylanLogPlug.h" // for LogPlug 00031 #include "CeylanOperators.h" // for toString 00032 00033 #include "CeylanVector2.h" // for Vector2 00034 #include "CeylanVector3.h" // for Vector3 00035 00036 #include "CeylanMathsBasic.h" // for AngleInDegrees 00037 00038 00039 using std::string ; 00040 00041 00042 using namespace Ceylan ; 00043 using namespace Ceylan::Maths ; 00044 using namespace Ceylan::Maths::Linear ; 00045 00046 00047 00048 00049 // 2D section. 00050 00051 00052 Endomorphism2DFunctor::Endomorphism2DFunctor() 00053 { 00054 00055 } 00056 00057 00058 00059 Endomorphism2DFunctor::~Endomorphism2DFunctor() throw() 00060 { 00061 00062 } 00063 00064 00065 00066 const string Endomorphism2DFunctor::toString( VerbosityLevels level ) const 00067 { 00068 00069 return "Functor encapsulating a 2D endomorphism" ; 00070 00071 } 00072 00073 00074 00075 00076 Rotation2DFunctor::Rotation2DFunctor( AngleInDegrees angle ) : 00077 _angle( 0 ) 00078 { 00079 00080 _angle = DegreeToRadian( angle ) ; 00081 00082 } 00083 00084 00085 00086 Rotation2DFunctor::~Rotation2DFunctor() throw() 00087 { 00088 00089 } 00090 00091 00092 Vector2 Rotation2DFunctor::operator() ( const Vector2 & v ) 00093 { 00094 00095 // Hardcoded 2x2 rotation: 00096 00097 return Vector2( 00098 Cos( _angle ) * v.getElementAt( 0 ) 00099 - Sin( _angle) * v.getElementAt( 1 ), 00100 Sin( _angle ) * v.getElementAt( 0 ) 00101 + Cos( _angle) * v.getElementAt( 1 ) 00102 ) ; 00103 00104 } 00105 00106 00107 00108 const string Rotation2DFunctor::toString( VerbosityLevels level ) const 00109 { 00110 00111 return Endomorphism2DFunctor::toString() + ": rotation of angle " 00112 + Ceylan::toString( _angle ) + " radians" ; 00113 00114 } 00115 00116 00117 00118 00119 // 3D section. 00120 00121 00122 Endomorphism3DFunctor::Endomorphism3DFunctor() 00123 { 00124 00125 } 00126 00127 00128 Endomorphism3DFunctor::~Endomorphism3DFunctor() throw() 00129 { 00130 00131 } 00132 00133 00134 00135 const string Endomorphism3DFunctor::toString( VerbosityLevels level ) const 00136 { 00137 00138 return "Functor encapsulating a 3D endomorphism" ; 00139 00140 } 00141 00142 00143 00144 LineProjection3DFunctor::LineProjection3DFunctor( const Vector3 & axis ) : 00145 _axis( axis ) 00146 { 00147 00148 _axis.normalize() ; 00149 00150 } 00151 00152 00153 00154 LineProjection3DFunctor::~LineProjection3DFunctor() throw() 00155 { 00156 00157 } 00158 00159 00160 00161 Vector3 LineProjection3DFunctor::operator() ( const Vector3 & v ) 00162 { 00163 00164 return ( v | _axis ) * _axis ; 00165 00166 } 00167 00168 00169 00170 const string LineProjection3DFunctor::toString( VerbosityLevels level ) const 00171 { 00172 00173 return Endomorphism3DFunctor::toString() + ": line projection on axis " 00174 + _axis.toString() ; 00175 00176 } 00177 00178 00179 00180 Rotation3DFunctor::Rotation3DFunctor( const Vector3 & axis, 00181 AngleInDegrees angle ) : 00182 _axis( axis ), 00183 _angle( 0 ) 00184 { 00185 00186 _axis.normalize() ; 00187 _angle = DegreeToRadian( angle ) ; 00188 00189 } 00190 00191 00192 00193 Rotation3DFunctor::~Rotation3DFunctor() throw() 00194 { 00195 00196 } 00197 00198 00199 00200 Vector3 Rotation3DFunctor::operator() ( const Vector3 & v ) 00201 { 00202 00203 return ( Cos( _angle )*v + 00204 ( ( v | _axis ) * ( 1 - Cos( _angle ) ) ) * _axis 00205 + Sin( _angle) * ( _axis ^ v ) ) ; 00206 00207 } 00208 00209 00210 00211 const string Rotation3DFunctor::toString( VerbosityLevels level ) const 00212 { 00213 00214 return Endomorphism3DFunctor::toString() + ": rotation around axis " 00215 + _axis.toString() + " of angle " 00216 + Ceylan::toString( _angle ) + " radians" ; 00217 00218 } 00219