Clipper
rotation.h
1 
4 //C Copyright (C) 2000-2006 Kevin Cowtan and University of York
5 //L
6 //L This library is free software and is distributed under the terms
7 //L and conditions of version 2.1 of the GNU Lesser General Public
8 //L Licence (LGPL) with the following additional clause:
9 //L
10 //L `You may also combine or link a "work that uses the Library" to
11 //L produce a work containing portions of the Library, and distribute
12 //L that work under terms of your choice, provided that you give
13 //L prominent notice with each copy of the work that the specified
14 //L version of the Library is used in it, and that you include or
15 //L provide public access to the complete corresponding
16 //L machine-readable source code for the Library including whatever
17 //L changes were used in the work. (i.e. If you make changes to the
18 //L Library you must distribute those, but you do not need to
19 //L distribute source or object code to those portions of the work
20 //L not covered by this licence.)'
21 //L
22 //L Note that this clause grants an additional right and does not impose
23 //L any additional restriction, and so does not affect compatibility
24 //L with the GNU General Public Licence (GPL). If you wish to negotiate
25 //L other terms, please contact the maintainer.
26 //L
27 //L You can redistribute it and/or modify the library under the terms of
28 //L the GNU Lesser General Public License as published by the Free Software
29 //L Foundation; either version 2.1 of the License, or (at your option) any
30 //L later version.
31 //L
32 //L This library is distributed in the hope that it will be useful, but
33 //L WITHOUT ANY WARRANTY; without even the implied warranty of
34 //L MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35 //L Lesser General Public License for more details.
36 //L
37 //L You should have received a copy of the CCP4 licence and/or GNU
38 //L Lesser General Public License along with this library; if not, write
39 //L to the CCP4 Secretary, Daresbury Laboratory, Warrington WA4 4AD, UK.
40 //L The GNU Lesser General Public can also be obtained by writing to the
41 //L Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
42 //L MA 02111-1307 USA
43 
44 
45 #ifndef CLIPPER_ROTATION
46 #define CLIPPER_ROTATION
47 
48 
49 #include "clipper_types.h"
50 
51 
52 namespace clipper
53 {
54 
55  // forward definition
56  class Rotation;
57 
58 
60  /* Rotations are generally handled through the clipper::Rotation
61  class. This class only exists for conversion purposes.
62 
63  This particular class represents generic Euler angles. The
64  convention is selected from the 24 possible conventions according
65  to the template parameter. The integer convention code is
66  enumerated in the Rotation::EULERtype enumation in the form
67  Rotation::EulerZYZr, Rotation::EulerXYZs etc., where the X/Y/Z
68  indicates the axes of rotation in order, and the r/s indicates
69  static or rotating axes. The type of an Euler class is also given
70  as a prefix to the result of format(). */
71  template<int T> class Euler {
72  public:
74  Euler() {}
76  Euler( const ftype& alpha, const ftype& beta, const ftype& gamma ) :
77  alpha_(alpha), beta_(beta), gamma_(gamma) {}
79  Euler( const Rotation& rot );
81  Rotation rotation() const;
82  const ftype& alpha() const { return alpha_; }
83  const ftype& beta() const { return beta_; }
84  const ftype& gamma() const { return gamma_; }
85  String format() const;
86  private:
87  static void params( int& r1, int& r2, int& r3, int& s );
88  ftype alpha_, beta_, gamma_;
89  };
90 
92  /* Rotations are generally handled through the clipper::Rotation
93  class. This class only exists for conversion purposes.
94 
95  This particular class represents Euler_ccp4 angles according to the
96  CCP4 standard, i.e.
97  - Rotation 1 (alpha) about K,
98  - Rotation 2 (beta) about the new J,
99  - Rotation 3 (gamma) about the new K. */
100  class Euler_ccp4 {
101  public:
105  Euler_ccp4( const ftype& alpha, const ftype& beta, const ftype& gamma ) :
106  alpha_(alpha), beta_(beta), gamma_(gamma) {}
107  const ftype& alpha() const { return alpha_; }
108  const ftype& beta() const { return beta_; }
109  const ftype& gamma() const { return gamma_; }
110  String format() const;
111  private:
112  ftype alpha_, beta_, gamma_;
113  };
114 
116  /* Rotations are generally handled through the clipper::Rotation
117  class. This class only exists for conversion purposes.
118 
119  This particular class represents Polar_ccp4 angles according to the
120  CCP4 standard, i.e.
121  - omega gives inclination of rotation axis to K axis,
122  - phi gives anticlockwise rotation from I to projection of
123  rotation axis onto I-J plane,
124  - kappa is the rotation about the rotation axis. */
125  class Polar_ccp4 {
126  public:
130  Polar_ccp4( const ftype& omega, const ftype& phi, const ftype& kappa ) :
131  omega_(omega), phi_(phi), kappa_(kappa) {}
132  const ftype& psi() const { return omega_; }
133  const ftype& omega() const { return omega_; }
134  const ftype& phi() const { return phi_; }
135  const ftype& kappa() const { return kappa_; }
136  String format() const;
137  private:
138  ftype omega_, phi_, kappa_;
139  };
140 
142 
145  class Rotation {
146  public:
148  Rotation() {}
150  template<int T> explicit Rotation( const Euler<T>& euler )
151  { (*this) = euler.rotation(); }
153  explicit Rotation( const Euler_ccp4& euler );
155  explicit Rotation( const Polar_ccp4& polar );
157  explicit Rotation( const Mat33<>& matrix );
159  Rotation( const ftype& w, const ftype& x, const ftype& y, const ftype& z )
160  : w_(w), x_(x), y_(y), z_(z) {}
161  const ftype& w() const { return w_; }
162  const ftype& x() const { return x_; }
163  const ftype& y() const { return y_; }
164  const ftype& z() const { return z_; }
165  template<int T> Euler<T> euler() const
166  { return Euler<T>( *this ); }
167  Euler_ccp4 euler_ccp4() const;
168  Polar_ccp4 polar_ccp4() const;
169  Mat33<> matrix() const;
170  const Rotation& norm();
173  ftype abs_angle() const;
175  Rotation inverse() const { return Rotation( w_, -x_, -y_, -z_ ); }
177  static Rotation zero() { return Rotation( 1.0, 0.0, 0.0, 0.0 ); }
179  static Rotation null() { return Rotation( Util::nan(), 0.0, 0.0, 0.0 ); }
181  bool is_null() const { return Util::is_nan( w_ ); }
183  friend Rotation operator* ( const Rotation& r1, const Rotation& r2 );
184  String format() const;
185  enum EULERtype { EulerXYZr,EulerXYZs,EulerXYXr,EulerXYXs,
187  EulerXZXr,EulerXZXs,EulerXZYr,EulerXZYs,
188  EulerYZXr,EulerYZXs,EulerYZYr,EulerYZYs,
189  EulerYXYr,EulerYXYs,EulerYXZr,EulerYXZs,
190  EulerZXYr,EulerZXYs,EulerZXZr,EulerZXZs,
191  EulerZYZr,EulerZYZs,EulerZYXr,EulerZYXs };
192  protected:
193  ftype w_, x_, y_, z_;
194  };
195 
196 
197 } // namespace clipper
198 
199 #endif
Euler_ccp4()
constructor: null
Definition: rotation.h:103
static Rotation null()
return null rotation
Definition: rotation.h:179
Euler_ccp4 angle class.
Definition: rotation.h:100
const ftype & alpha() const
return alpha
Definition: rotation.h:82
const ftype & alpha() const
return alpha
Definition: rotation.h:107
const ftype & y() const
return y component
Definition: rotation.h:163
friend Rotation operator*(const Rotation &r1, const Rotation &r2)
combine two rotations
Definition: rotation.cpp:298
const ftype & gamma() const
return gamma
Definition: rotation.h:84
Rotation inverse() const
return inverse rotation
Definition: rotation.h:175
static const ftype & nan()
fast Util::nan() value
Definition: clipper_util.h:67
Rotation(const ftype &w, const ftype &x, const ftype &y, const ftype &z)
constructor: from components
Definition: rotation.h:159
const ftype & kappa() const
return kappa
Definition: rotation.h:135
ftype64 ftype
ftype definition for floating point representation
Definition: clipper_precision.h:58
const Rotation & norm()
normalise this quaternion
Definition: rotation.cpp:206
Polar_ccp4 angle class.
Definition: rotation.h:125
Euler(const ftype &alpha, const ftype &beta, const ftype &gamma)
constructor: from specified angles
Definition: rotation.h:76
Rotation class.
Definition: rotation.h:145
Euler_ccp4(const ftype &alpha, const ftype &beta, const ftype &gamma)
constructor: from specified angles
Definition: rotation.h:105
Mat33 matrix() const
return 3x3 matrix
Definition: rotation.cpp:268
const ftype & w() const
return w component
Definition: rotation.h:161
Rotation()
null constructor
Definition: rotation.h:148
String format() const
return formatted String representation
Definition: rotation.cpp:123
Euler< T > euler() const
< return Euler angles
Definition: rotation.h:165
const ftype & omega() const
return omega
Definition: rotation.h:133
String extension with simple parsing methods.
Definition: clipper_types.h:64
static bool is_nan(const ftype32 f)
fast Util::nan() test
Definition: clipper_util.h:82
Euler_ccp4 euler_ccp4() const
return Euler_ccp4 angles
Definition: rotation.cpp:231
Euler angle class.
Definition: rotation.h:71
ftype abs_angle() const
return absolute rotation angle
Definition: rotation.cpp:224
String format() const
return formatted String representation
Definition: rotation.cpp:139
const ftype & phi() const
return phi
Definition: rotation.h:134
const ftype & x() const
return x component
Definition: rotation.h:162
Rotation rotation() const
return rotation
Definition: rotation.cpp:102
const ftype & gamma() const
return gamma
Definition: rotation.h:109
String format() const
return formatted String representation
Definition: rotation.cpp:306
static Rotation zero()
return zero rotation
Definition: rotation.h:177
const ftype & beta() const
return beta
Definition: rotation.h:83
Rotation(const Euler< T > &euler)
constructor: from generic Euler
Definition: rotation.h:150
Polar_ccp4 polar_ccp4() const
return Polar_ccp4 angles
Definition: rotation.cpp:252
const ftype & beta() const
return beta
Definition: rotation.h:108
Polar_ccp4()
null constructor
Definition: rotation.h:128
bool is_null() const
test for null (uninitialised) rotation
Definition: rotation.h:181
Euler()
constructor: null
Definition: rotation.h:74
String format() const
return formatted String representation
Definition: rotation.cpp:142
Polar_ccp4(const ftype &omega, const ftype &phi, const ftype &kappa)
constructor: from specified angles
Definition: rotation.h:130
const ftype & psi() const
return omega
Definition: rotation.h:132
const ftype & z() const
return z component
Definition: rotation.h:164
EULERtype
Enumeration of Euler conventions.
Definition: rotation.h:186
3x3-matrix class
Definition: clipper_types.h:182