# | Line 1 | Line 1 | |
---|---|---|
1 | < | /* |
2 | < | * Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project |
3 | < | * |
4 | < | * Contact: oopse@oopse.org |
5 | < | * |
6 | < | * This program is free software; you can redistribute it and/or |
7 | < | * modify it under the terms of the GNU Lesser General Public License |
8 | < | * as published by the Free Software Foundation; either version 2.1 |
9 | < | * of the License, or (at your option) any later version. |
10 | < | * All we ask is that proper credit is given for our work, which includes |
11 | < | * - but is not limited to - adding the above copyright notice to the beginning |
12 | < | * of your source code files, and to any copyright notice that you may distribute |
13 | < | * with programs based on this work. |
14 | < | * |
15 | < | * This program is distributed in the hope that it will be useful, |
16 | < | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | < | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | < | * GNU Lesser General Public License for more details. |
19 | < | * |
20 | < | * You should have received a copy of the GNU Lesser General Public License |
21 | < | * along with this program; if not, write to the Free Software |
22 | < | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1 | > | /* |
2 | > | * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 | * | |
4 | + | * The University of Notre Dame grants you ("Licensee") a |
5 | + | * non-exclusive, royalty free, license to use, modify and |
6 | + | * redistribute this software in source and binary code form, provided |
7 | + | * that the following conditions are met: |
8 | + | * |
9 | + | * 1. Acknowledgement of the program authors must be made in any |
10 | + | * publication of scientific results based in part on use of the |
11 | + | * program. An acceptable form of acknowledgement is citation of |
12 | + | * the article in which the program was described (Matthew |
13 | + | * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 | + | * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 | + | * Parallel Simulation Engine for Molecular Dynamics," |
16 | + | * J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 | + | * |
18 | + | * 2. Redistributions of source code must retain the above copyright |
19 | + | * notice, this list of conditions and the following disclaimer. |
20 | + | * |
21 | + | * 3. Redistributions in binary form must reproduce the above copyright |
22 | + | * notice, this list of conditions and the following disclaimer in the |
23 | + | * documentation and/or other materials provided with the |
24 | + | * distribution. |
25 | + | * |
26 | + | * This software is provided "AS IS," without a warranty of any |
27 | + | * kind. All express or implied conditions, representations and |
28 | + | * warranties, including any implied warranty of merchantability, |
29 | + | * fitness for a particular purpose or non-infringement, are hereby |
30 | + | * excluded. The University of Notre Dame and its licensors shall not |
31 | + | * be liable for any damages suffered by licensee as a result of |
32 | + | * using, modifying or distributing the software or its |
33 | + | * derivatives. In no event will the University of Notre Dame or its |
34 | + | * licensors be liable for any lost revenue, profit or data, or for |
35 | + | * direct, indirect, special, consequential, incidental or punitive |
36 | + | * damages, however caused and regardless of the theory of liability, |
37 | + | * arising out of the use of or inability to use software, even if the |
38 | + | * University of Notre Dame has been advised of the possibility of |
39 | + | * such damages. |
40 | */ | |
41 | < | |
41 | > | |
42 | /** | |
43 | * @file Quaternion.hpp | |
44 | * @author Teng Lin | |
# | Line 53 | Line 69 | namespace oopse{ | |
69 | ||
70 | /** Constructs and initializes a Quaternion from w, x, y, z values */ | |
71 | Quaternion(Real w, Real x, Real y, Real z) { | |
72 | < | data_[0] = w; |
73 | < | data_[1] = x; |
74 | < | data_[2] = y; |
75 | < | data_[3] = z; |
72 | > | this->data_[0] = w; |
73 | > | this->data_[1] = x; |
74 | > | this->data_[2] = y; |
75 | > | this->data_[3] = z; |
76 | } | |
77 | ||
78 | /** Constructs and initializes a Quaternion from a Vector<Real,4> */ | |
# | Line 79 | Line 95 | namespace oopse{ | |
95 | * @return the value of the first element of this quaternion | |
96 | */ | |
97 | Real w() const { | |
98 | < | return data_[0]; |
98 | > | return this->data_[0]; |
99 | } | |
100 | ||
101 | /** | |
# | Line 87 | Line 103 | namespace oopse{ | |
103 | * @return the reference of the first element of this quaternion | |
104 | */ | |
105 | Real& w() { | |
106 | < | return data_[0]; |
106 | > | return this->data_[0]; |
107 | } | |
108 | ||
109 | /** | |
# | Line 95 | Line 111 | namespace oopse{ | |
111 | * @return the value of the first element of this quaternion | |
112 | */ | |
113 | Real x() const { | |
114 | < | return data_[1]; |
114 | > | return this->data_[1]; |
115 | } | |
116 | ||
117 | /** | |
# | Line 103 | Line 119 | namespace oopse{ | |
119 | * @return the reference of the second element of this quaternion | |
120 | */ | |
121 | Real& x() { | |
122 | < | return data_[1]; |
122 | > | return this->data_[1]; |
123 | } | |
124 | ||
125 | /** | |
# | Line 111 | Line 127 | namespace oopse{ | |
127 | * @return the value of the third element of this quaternion | |
128 | */ | |
129 | Real y() const { | |
130 | < | return data_[2]; |
130 | > | return this->data_[2]; |
131 | } | |
132 | ||
133 | /** | |
# | Line 119 | Line 135 | namespace oopse{ | |
135 | * @return the reference of the third element of this quaternion | |
136 | */ | |
137 | Real& y() { | |
138 | < | return data_[2]; |
138 | > | return this->data_[2]; |
139 | } | |
140 | ||
141 | /** | |
# | Line 127 | Line 143 | namespace oopse{ | |
143 | * @return the value of the fourth element of this quaternion | |
144 | */ | |
145 | Real z() const { | |
146 | < | return data_[3]; |
146 | > | return this->data_[3]; |
147 | } | |
148 | /** | |
149 | * Returns the reference of the fourth element of this quaternion. | |
150 | * @return the reference of the fourth element of this quaternion | |
151 | */ | |
152 | Real& z() { | |
153 | < | return data_[3]; |
153 | > | return this->data_[3]; |
154 | } | |
155 | ||
156 | /** | |
# | Line 145 | Line 161 | namespace oopse{ | |
161 | inline bool operator ==(const Quaternion<Real>& q) { | |
162 | ||
163 | for (unsigned int i = 0; i < 4; i ++) { | |
164 | < | if (!equal(data_[i], q[i])) { |
164 | > | if (!equal(this->data_[i], q[i])) { |
165 | return false; | |
166 | } | |
167 | } | |
# | Line 178 | Line 194 | namespace oopse{ | |
194 | void mul(const Quaternion<Real>& q) { | |
195 | Quaternion<Real> tmp(*this); | |
196 | ||
197 | < | data_[0] = (tmp[0]*q[0]) -(tmp[1]*q[1]) - (tmp[2]*q[2]) - (tmp[3]*q[3]); |
198 | < | data_[1] = (tmp[0]*q[1]) + (tmp[1]*q[0]) + (tmp[2]*q[3]) - (tmp[3]*q[2]); |
199 | < | data_[2] = (tmp[0]*q[2]) + (tmp[2]*q[0]) + (tmp[3]*q[1]) - (tmp[1]*q[3]); |
200 | < | data_[3] = (tmp[0]*q[3]) + (tmp[3]*q[0]) + (tmp[1]*q[2]) - (tmp[2]*q[1]); |
197 | > | this->data_[0] = (tmp[0]*q[0]) -(tmp[1]*q[1]) - (tmp[2]*q[2]) - (tmp[3]*q[3]); |
198 | > | this->data_[1] = (tmp[0]*q[1]) + (tmp[1]*q[0]) + (tmp[2]*q[3]) - (tmp[3]*q[2]); |
199 | > | this->data_[2] = (tmp[0]*q[2]) + (tmp[2]*q[0]) + (tmp[3]*q[1]) - (tmp[1]*q[3]); |
200 | > | this->data_[3] = (tmp[0]*q[3]) + (tmp[3]*q[0]) + (tmp[1]*q[2]) - (tmp[2]*q[1]); |
201 | } | |
202 | ||
203 | void mul(const Real& s) { | |
204 | < | data_[0] *= s; |
205 | < | data_[1] *= s; |
206 | < | data_[2] *= s; |
207 | < | data_[3] *= s; |
204 | > | this->data_[0] *= s; |
205 | > | this->data_[1] *= s; |
206 | > | this->data_[2] *= s; |
207 | > | this->data_[3] *= s; |
208 | } | |
209 | ||
210 | /** Set the value of this quaternion to the division of itself by another quaternion */ | |
# | Line 197 | Line 213 | namespace oopse{ | |
213 | } | |
214 | ||
215 | void div(const Real& s) { | |
216 | < | data_[0] /= s; |
217 | < | data_[1] /= s; |
218 | < | data_[2] /= s; |
219 | < | data_[3] /= s; |
216 | > | this->data_[0] /= s; |
217 | > | this->data_[1] /= s; |
218 | > | this->data_[2] /= s; |
219 | > | this->data_[3] /= s; |
220 | } | |
221 | ||
222 | Quaternion<Real>& operator *=(const Quaternion<Real>& q) { | |
# | Line 242 | Line 258 | namespace oopse{ | |
258 | Real y2; | |
259 | Real z2; | |
260 | ||
261 | < | if (!isNormalized()) |
262 | < | normalize(); |
261 | > | if (!this->isNormalized()) |
262 | > | this->normalize(); |
263 | ||
264 | w2 = w() * w(); | |
265 | x2 = x() * x(); |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |