-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquaternion.h
272 lines (221 loc) · 11.2 KB
/
quaternion.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#ifndef QUATERNION_H
#define QUATERNION_H
/******************************************
* C++ Quaternions
* Version: 1.0.9
* Author: Douglas Wilhelm Harder
* Date: 2008/03/03
*
* Copyright (c) 2006-2008 by Douglas Wilhelm Harder.
* All rights reserved.
******************************************/
#include <iostream>
#include <cmath>
#include <string>
template <typename T> class Quaternion;
template <typename T> std::ostream & operator << ( std::ostream &, const Quaternion<T> & );
template <typename T> Quaternion<T> operator + ( T, const Quaternion<T> & );
template <typename T> Quaternion<T> operator + ( long, const Quaternion<T> & );
template <typename T> Quaternion<T> operator - ( T, const Quaternion<T> & );
template <typename T> Quaternion<T> operator - ( long, const Quaternion<T> & );
template <typename T> Quaternion<T> operator * ( T, const Quaternion<T> & );
template <typename T> Quaternion<T> operator * ( long, const Quaternion<T> & );
template <typename T> Quaternion<T> operator / ( T, const Quaternion<T> & );
template <typename T> Quaternion<T> operator / ( long, const Quaternion<T> & );
template <typename T> bool operator == ( T, const Quaternion<T> & );
template <typename T> bool operator == ( long, const Quaternion<T> & );
template <typename T> bool operator != ( T, const Quaternion<T> & );
template <typename T> bool operator != ( long, const Quaternion<T> & );
template <typename T> T real( const Quaternion<T> & );
template <typename T> T imag_i( const Quaternion<T> & );
template <typename T> T imag_j( const Quaternion<T> & );
template <typename T> T imag_k( const Quaternion<T> & );
template <typename T> T csgn( const Quaternion<T> & );
template <typename T> T abs( const Quaternion<T> & );
template <typename T> T norm( const Quaternion<T> & );
template <typename T> T abs_imag( const Quaternion<T> & );
template <typename T> T norm_imag( const Quaternion<T> & );
template <typename T> T arg( const Quaternion<T> & );
template <typename T> Quaternion<T> imag( const Quaternion<T> & );
template <typename T> Quaternion<T> conj( const Quaternion<T> & );
template <typename T> Quaternion<T> signum( const Quaternion<T> & );
template <typename T> Quaternion<T> sqr( const Quaternion<T> & );
template <typename T> Quaternion<T> sqrt( const Quaternion<T> & );
template <typename T> Quaternion<T> rotate( const Quaternion<T> &, const Quaternion<T> & );
template <typename T> Quaternion<T> exp( const Quaternion<T> & );
template <typename T> Quaternion<T> log( const Quaternion<T> & );
template <typename T> Quaternion<T> log10( const Quaternion<T> & );
template <typename T> Quaternion<T> pow( const Quaternion<T> &, const Quaternion<T> & );
template <typename T> Quaternion<T> pow( const Quaternion<T> &, T );
template <typename T> Quaternion<T> inverse( const Quaternion<T> & );
template <typename T> Quaternion<T> cross(const Quaternion<T> & );
template <typename T> Quaternion<T> sin( const Quaternion<T> & );
template <typename T> Quaternion<T> cos( const Quaternion<T> & );
template <typename T> Quaternion<T> tan( const Quaternion<T> & );
template <typename T> Quaternion<T> sec( const Quaternion<T> & );
template <typename T> Quaternion<T> csc( const Quaternion<T> & );
template <typename T> Quaternion<T> cot( const Quaternion<T> & );
template <typename T> Quaternion<T> sinh( const Quaternion<T> & );
template <typename T> Quaternion<T> cosh( const Quaternion<T> & );
template <typename T> Quaternion<T> tanh( const Quaternion<T> & );
template <typename T> Quaternion<T> sech( const Quaternion<T> & );
template <typename T> Quaternion<T> csch( const Quaternion<T> & );
template <typename T> Quaternion<T> coth( const Quaternion<T> & );
template <typename T> Quaternion<T> asin( const Quaternion<T> &, const Quaternion<T> & = Quaternion<T>::I );
template <typename T> Quaternion<T> acos( const Quaternion<T> &, const Quaternion<T> & = Quaternion<T>::I );
template <typename T> Quaternion<T> atan( const Quaternion<T> & );
template <typename T> Quaternion<T> asec( const Quaternion<T> &, const Quaternion<T> & = Quaternion<T>::I );
template <typename T> Quaternion<T> acsc( const Quaternion<T> &, const Quaternion<T> & = Quaternion<T>::I );
template <typename T> Quaternion<T> acot( const Quaternion<T> & );
template <typename T> Quaternion<T> asinh( const Quaternion<T> & );
template <typename T> Quaternion<T> acosh( const Quaternion<T> &, const Quaternion<T> & = Quaternion<T>::I );
template <typename T> Quaternion<T> atanh( const Quaternion<T> &, const Quaternion<T> & = Quaternion<T>::I );
template <typename T> Quaternion<T> asech( const Quaternion<T> &, const Quaternion<T> & = Quaternion<T>::I );
template <typename T> Quaternion<T> acsch( const Quaternion<T> & );
template <typename T> Quaternion<T> acoth( const Quaternion<T> &, const Quaternion<T> & = Quaternion<T>::I );
template <typename T> Quaternion<T> bessel_J( int, const Quaternion<T> & );
template <typename T> Quaternion<T> floor( const Quaternion<T> & );
template <typename T> Quaternion<T> ceil( const Quaternion<T> & );
template <typename T> Quaternion<T> horner( const Quaternion<T> &, T *, unsigned int );
template <typename T> Quaternion<T> horner( const Quaternion<T> &, T *, T *, unsigned int );
template <typename T = double> class Quaternion {
private:
T r, i, j, k;
inline static Quaternion multiplier( T, T, const Quaternion & );
inline static Quaternion make_inf( T, T );
inline static Quaternion make_i( T, T );
public:
const static Quaternion ZERO;
const static Quaternion ONE;
const static Quaternion I;
const static Quaternion J;
const static Quaternion K;
const static Quaternion UNITS[4];
/******************************************
* Constructor and Copy Constructor
******************************************/
Quaternion( T, T, T, T );
Quaternion( T = 0.0 );
/******************************************
* Assignment Operator
******************************************/
const Quaternion & operator = ( const T & );
/******************************************
* Mutating Arithmetic Operators
******************************************/
Quaternion & operator += ( const Quaternion & );
Quaternion & operator -= ( const Quaternion & );
Quaternion & operator *= ( const Quaternion & );
Quaternion & operator /= ( const Quaternion & );
Quaternion & operator += ( T );
Quaternion & operator -= ( T );
Quaternion & operator *= ( T );
Quaternion & operator /= ( T );
Quaternion & operator ++();
Quaternion operator ++( int );
Quaternion & operator --();
Quaternion operator --( int );
/******************************************
* Real-valued Functions
******************************************/
T real() const;
T operator []( int ) const;
T &operator []( int );
T imag_i() const;
T imag_j() const;
T imag_k() const;
T csgn() const;
T abs() const;
T norm() const;
T abs_imag() const;
T norm_imag() const;
T arg() const;
/******************************************
* Quaternion-valued Functions
******************************************/
Quaternion imag() const;
Quaternion conj() const;
Quaternion operator * () const;
Quaternion signum() const;
Quaternion sqr() const;
Quaternion sqrt() const;
Quaternion rotate( const Quaternion & ) const;
/******************************************
* Boolean-valued Functions
******************************************/
bool is_imaginary() const;
bool is_inf() const;
bool is_nan() const;
bool is_neg_inf() const;
bool is_pos_inf() const;
bool is_real() const;
bool is_real_inf() const;
bool is_zero() const;
/******************************************
* Exponential and Logarithmic Functions
******************************************/
Quaternion exp() const;
Quaternion log() const;
Quaternion log10() const;
Quaternion pow(const Quaternion & w) const;
Quaternion pow(T x) const;
Quaternion inverse() const;
Quaternion cross(const Quaternion &) const;
/******************************************
* Trigonometric and Hyperbolic Functions
******************************************/
Quaternion sin() const; Quaternion cos() const; Quaternion tan() const;
Quaternion sec() const; Quaternion csc() const; Quaternion cot() const;
Quaternion sinh() const; Quaternion cosh() const; Quaternion tanh() const;
Quaternion sech() const; Quaternion csch() const; Quaternion coth() const;
Quaternion asin( const Quaternion & = I ) const;
Quaternion acos( const Quaternion & = I ) const; Quaternion atan() const;
Quaternion asec( const Quaternion & = I ) const;
Quaternion acsc( const Quaternion & = I ) const; Quaternion acot() const;
Quaternion asinh() const;
Quaternion acosh( const Quaternion & = I ) const;
Quaternion atanh( const Quaternion & = I ) const;
Quaternion asech( const Quaternion & = I ) const;
Quaternion acsch() const;
Quaternion acoth( const Quaternion & = I ) const;
Quaternion bessel_J( int ) const;
/******************************************
* Integer Functions
******************************************/
Quaternion ceil() const;
Quaternion floor() const;
/******************************************
* Horner's Rule
******************************************/
Quaternion horner( T *, unsigned int ) const;
Quaternion horner( T *, T *, unsigned int ) const;
/******************************************
* Random Factories
******************************************/
static Quaternion random();
static Quaternion random_imag();
static Quaternion random_real();
/******************************************
* Binary Arithmetic Operators
******************************************/
Quaternion operator + ( const Quaternion & ) const;
Quaternion operator + ( T ) const;
Quaternion operator - ( const Quaternion & ) const;
Quaternion operator - ( T ) const;
Quaternion operator * ( const Quaternion & ) const;
Quaternion operator * ( T ) const;
Quaternion operator / ( const Quaternion & ) const;
Quaternion operator / ( T ) const;
/******************************************
* Unary Arithmetic Operators
******************************************/
Quaternion operator - () const;
/******************************************
* Binary Boolean Operators
******************************************/
bool operator == ( const Quaternion & ) const;
bool operator == ( T ) const;
bool operator != ( const Quaternion & ) const;
bool operator != ( T ) const;
};
#endif // QUATERNION_H