RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
Euler.h
1/***********************************************************************
2 * The rDock program was developed from 1998 - 2006 by the software team
3 * at RiboTargets (subsequently Vernalis (R&D) Ltd).
4 * In 2006, the software was licensed to the University of York for
5 * maintenance and distribution.
6 * In 2012, Vernalis and the University of York agreed to release the
7 * program as Open Source software.
8 * This version is licensed under GNU-LGPL version 3.0 with support from
9 * the University of Barcelona.
10 * http://rdock.sourceforge.net/
11 ***********************************************************************/
12
13// Simple class to manage Euler angles
14// Main purpose is to provides conversion methods
15// to/from quaternion representation
16//
17// We adopt a modified "NASA Standard Aeroplane" convention
18// in which the y and z axes are swapped relative to the definition in
19// http://www.euclideanspace.com/maths/geometry/rotations/euler/index.htm
20//(and related links).
21// This should be equivalent to the VRML convention.
22//
23// An object's orientation is defined in terms of:
24//
25// 1) heading (-PI to +PI) (rotation around z) (y in NASA Aeroplane)
26// 2) attitude (-PI/2 to +PI/2) (rotation around y) (z in NASA Aeroplane)
27// 3) bank (-PI to +PI) (rotation around x)
28//
29// See http://www.euclideanspace.com/maths/geometry/rotations/euler/index.htm
30// and related links for definitions and conversion equations.
31//
32// NOTE: This class is designed to provide fast conversion between Euler angles
33// and quaternions. It is the callers responsibility to ensure that:
34// a) heading, attitude and bank angles are within range
35// b) quaternions passed to the constructor and SetQuat are of unit length
36// Run-time exceptions may occur if these conditions are not met.
37#ifndef RBTEULER_H_
38#define RBTEULER_H_
39
40#include "rxdock/Quat.h"
41
42#include <nlohmann/json.hpp>
43
44using json = nlohmann::json;
45
46namespace rxdock {
47
48class Euler {
49public:
50 // Constructor accepting values for heading, attitude and bank (radians).
51 // NOTE: For performance reasons, no checks are made that the values
52 // are within range
53 Euler(double heading = 0.0, double attitude = 0.0, double bank = 0.0)
54 : m_heading(heading), m_attitude(attitude), m_bank(bank) {}
55 // Constructor accepting a quaternion.
56 // Quaternion is converted to Euler angle representation
57 // NOTE: For performance reasons, q is assumed to be of unit length
58 // and no further checks are made.
59 Euler(const Quat &q) { FromQuat(q); }
60
61 // Returns true if all three Euler angles are within their
62 // standard ranges
63 bool isStandardised() const {
64 return (m_heading >= -M_PI) && (m_heading <= M_PI) &&
65 (m_attitude >= -M_PI / 2.0) && (m_attitude <= M_PI / 2.0) &&
66 (m_bank >= -M_PI) && (m_bank <= M_PI);
67 }
68 // Standardises the Euler angles by conversion to/from quaternion
69 void Standardise() {
70 if (!isStandardised())
71 FromQuat(ToQuat());
72 }
73
74 // Gets the current heading angle (radians)
75 double GetHeading() const { return m_heading; }
76 // Gets the current attitude angle (radians)
77 double GetAttitude() const { return m_attitude; }
78 // Gets the current bank angle (radians)
79 double GetBank() const { return m_bank; }
80 // Gets the equivalent quaternion representation
81 // NOTE: For performance reasons, no checks are made that the current
82 // Euler angles are within range prior to the conversion.
83 RBTDLL_EXPORT Quat ToQuat() const;
84 // Updates the Euler angles from a quaternion representation
85 // NOTE: For performance reasons, q is assumed to be of unit length
86 // and no further checks are made.
87 RBTDLL_EXPORT void FromQuat(const Quat &q);
88 // Convenience method to rotate orientation by a quaternion
89 void Rotate(const Quat &q) { FromQuat(q * ToQuat()); }
90 void Rotate(const Vector &axis, double theta) { Rotate(Quat(axis, theta)); }
91
92 // Insertion operator
93 friend std::ostream &operator<<(std::ostream &s, const Euler &euler) {
94 return s << "Heading = " << euler.m_heading
95 << ", Attitude = " << euler.m_attitude
96 << ", Bank = " << euler.m_bank;
97 }
98
99 friend void to_json(json &j, const Euler &eul);
100 friend void from_json(const json &j, Euler &eul);
101
102private:
103 double m_heading; // heading angle (radians)
104 double m_attitude; // attitude angle (radians)
105 double m_bank; // bank angle (radians)
106};
107
108void to_json(json &j, const Euler &eul);
109void from_json(const json &j, Euler &eul);
110
111} // namespace rxdock
112
113#endif /*RBTEULER_H_*/
Definition Coord.h:45
Definition Euler.h:48
Definition Quat.h:24