BWAPI
|
00001 // Copyright (c) 2000 Utrecht University (The Netherlands), 00002 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany), 00003 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg 00004 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria), 00005 // and Tel-Aviv University (Israel). All rights reserved. 00006 // 00007 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00008 // modify it under the terms of the GNU Lesser General Public License as 00009 // published by the Free Software Foundation; version 2.1 of the License. 00010 // See the file LICENSE.LGPL distributed with CGAL. 00011 // 00012 // Licensees holding a valid commercial license may use this file in 00013 // accordance with the commercial license agreement provided with the software. 00014 // 00015 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 // 00018 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Cartesian_kernel/include/CGAL/Cartesian/Rotation_rep_2.h $ 00019 // $Id: Rotation_rep_2.h 32863 2006-08-01 08:18:19Z spion $ 00020 // 00021 // 00022 // Author(s) : Andreas Fabri, Herve Bronnimann 00023 00024 #ifndef CGAL_CARTESIAN_ROTATION_REP_2_H 00025 #define CGAL_CARTESIAN_ROTATION_REP_2_H 00026 00027 #include <CGAL/rational_rotation.h> 00028 00029 CGAL_BEGIN_NAMESPACE 00030 00031 template < class R > 00032 class Rotation_repC2: public Aff_transformation_rep_baseC2<R> 00033 { 00034 friend class Aff_transformation_repC2<R>; 00035 friend class Translation_repC2<R>; 00036 friend class Scaling_repC2<R>; 00037 00038 public: 00039 typedef Aff_transformation_rep_baseC2<R> Aff_t_base; 00040 typedef typename Aff_t_base::FT FT; 00041 typedef typename Aff_t_base::Point_2 Point_2; 00042 typedef typename Aff_t_base::Vector_2 Vector_2; 00043 typedef typename Aff_t_base::Direction_2 Direction_2; 00044 typedef typename Aff_t_base::Aff_transformation_2 Aff_transformation_2; 00045 typedef Aff_transformation_repC2<R> Transformation; 00046 typedef Translation_repC2<R> Translation; 00047 typedef Rotation_repC2<R> Rotation; 00048 typedef Scaling_repC2<R> Scaling; 00049 00050 Rotation_repC2() {} 00051 00052 Rotation_repC2(const FT &sinus, const FT &cosinus) 00053 : sinus_(sinus), cosinus_(cosinus) {} 00054 00055 Rotation_repC2(const Direction_2 &d, 00056 const FT &eps_num, 00057 const FT &eps_den = FT(1)) 00058 { 00059 FT sin_num; 00060 FT cos_num; 00061 FT denom; 00062 00063 rational_rotation_approximation(d.dx(), 00064 d.dy(), 00065 sin_num, 00066 cos_num, 00067 denom, 00068 eps_num, 00069 eps_den); 00070 sinus_ = sin_num/denom; 00071 cosinus_ = cos_num/denom; 00072 } 00073 00074 Point_2 transform(const Point_2 &p) const 00075 { 00076 return Point_2(cosinus_ * p.x() - sinus_ * p.y(), 00077 sinus_ * p.x() + cosinus_ * p.y()); 00078 } 00079 00080 Vector_2 transform(const Vector_2 &v) const 00081 { 00082 return Vector_2(cosinus_ * v.x() - sinus_ * v.y(), 00083 sinus_ * v.x() + cosinus_ * v.y()); 00084 } 00085 00086 Direction_2 transform(const Direction_2 &d) const 00087 { 00088 return Direction_2(cosinus_ * d.dx() - sinus_ * d.dy(), 00089 sinus_ * d.dx() + cosinus_ * d.dy()); 00090 } 00091 00092 Aff_transformation_2 inverse() const 00093 { 00094 return Aff_transformation_2(ROTATION, - sinus_, cosinus_, FT(1)); 00095 } 00096 00097 Aff_transformation_2 operator*(const Aff_t_base &t) const 00098 { 00099 return t.compose(*this); 00100 } 00101 00102 Aff_transformation_2 compose(const Translation &t) const 00103 { 00104 return Aff_transformation_2(cosinus_, 00105 -sinus_, 00106 t.translationvector_.x(), 00107 sinus_, 00108 cosinus_, 00109 t.translationvector_.y()); 00110 } 00111 00112 Aff_transformation_2 compose(const Rotation &t) const 00113 { 00114 return Aff_transformation_2(ROTATION, 00115 t.sinus_*cosinus_ + t.cosinus_*sinus_, 00116 t.cosinus_*cosinus_-t.sinus_*sinus_ ); 00117 } 00118 00119 Aff_transformation_2 compose(const Scaling &t) const 00120 { 00121 return Aff_transformation_2(t.scalefactor_*cosinus_, 00122 t.scalefactor_*-sinus_, 00123 t.scalefactor_*sinus_, 00124 t.scalefactor_*cosinus_); 00125 } 00126 00127 Aff_transformation_2 compose(const Transformation &t) const 00128 { 00129 return Aff_transformation_2(cosinus_*t.t11 + sinus_*t.t12, 00130 -sinus_*t.t11 + cosinus_*t.t12, 00131 t.t13, 00132 cosinus_*t.t21 + sinus_*t.t22, 00133 -sinus_*t.t21 + cosinus_*t.t22, 00134 t.t23); 00135 } 00136 00137 bool is_even() const 00138 { 00139 return true; 00140 } 00141 00142 FT cartesian(int i, int j) const 00143 { 00144 switch (i) 00145 { 00146 case 0: switch (j) 00147 { 00148 case 0: return cosinus_; 00149 case 1: return -sinus_; 00150 case 2: return FT(0); 00151 } 00152 case 1: switch (j) 00153 { 00154 case 0: return sinus_; 00155 case 1: return cosinus_; 00156 case 2: return FT(0); 00157 } 00158 case 2: switch (j) 00159 { 00160 case 0: return FT(0); 00161 case 1: return FT(0); 00162 case 2: return FT(1); 00163 } 00164 } 00165 return FT(0); 00166 } 00167 00168 std::ostream &print(std::ostream &os) const 00169 { 00170 os << "Aff_transformationC2(" << sinus_ << ", " << cosinus_ << ")"; 00171 return os; 00172 } 00173 00174 private: 00175 FT sinus_, cosinus_; 00176 }; 00177 00178 CGAL_END_NAMESPACE 00179 00180 #endif // CGAL_CARTESIAN_ROTATION_REP_2_H