5
@deftypefn {Function File} {@var{q} =} quaternion (@var{w})
6
@deftypefnx {Function File} {@var{q} =} quaternion (@var{x}, @var{y}, @var{z})
7
@deftypefnx {Function File} {@var{q} =} quaternion (@var{w}, @var{x}, @var{y}, @var{z})
8
Constructor for quaternions - create or convert to quaternion.
11
q = w + x*i + y*j + z*k
14
Arguments @var{w}, @var{x}, @var{y} and @var{z} can be scalars,
15
matrices or n-dimensional arrays, but they must be real-valued
17
If scalar part @var{w} or components @var{x}, @var{y} and @var{z}
18
of the vector part are not specified, zero matrices of appropriate
24
octave:1> q = quaternion (2)
27
octave:2> q = quaternion (3, 4, 5)
30
octave:3> q = quaternion (2, 3, 4, 5)
36
octave:4> w = [2, 6, 10; 14, 18, 22];
37
octave:5> x = [3, 7, 11; 15, 19, 23];
38
octave:6> y = [4, 8, 12; 16, 20, 24];
39
octave:7> z = [5, 9, 13; 17, 21, 25];
40
octave:8> q = quaternion (w, x, y, z)
65
@deftypefn {Function File} {} qi
66
Create x-component of a quaternion's vector part.
69
q = w + x*qi + y*qj + z*qk
75
octave:1> q1 = quaternion (1, 2, 3, 4)
77
octave:2> q2 = 1 + 2*qi + 3*qj + 4*qk
87
@deftypefn {Function File} {} qj
88
Create y-component of a quaternion's vector part.
91
q = w + x*qi + y*qj + z*qk
97
octave:1> q1 = quaternion (1, 2, 3, 4)
99
octave:2> q2 = 1 + 2*qi + 3*qj + 4*qk
100
q2 = 1 + 2i + 3j + 4k
109
@deftypefn {Function File} {} qk
110
Create z-component of a quaternion's vector part.
113
q = w + x*qi + y*qj + z*qk
119
octave:1> q1 = quaternion (1, 2, 3, 4)
120
q1 = 1 + 2i + 3j + 4k
121
octave:2> q2 = 1 + 2*qi + 3*qj + 4*qk
122
q2 = 1 + 2i + 3j + 4k
131
@deftypefn {Function File} {[@var{axis}, @var{angle}] =} q2rot (@var{q})
132
Extract vector/angle form of a unit quaternion @var{q}.
137
Unit quaternion describing the rotation.
143
Eigenaxis as a 3-d unit vector @code{[x, y, z]}.
145
Rotation angle in radians. The positive direction is
146
determined by the right-hand rule applied to @var{axis}.
152
octave:1> axis = [0, 0, 1]
155
octave:2> angle = pi/4
157
octave:3> q = rot2q (axis, angle)
158
q = 0.9239 + 0i + 0j + 0.3827k
159
octave:4> [vv, th] = q2rot (q)
163
octave:5> theta = th*180/pi
173
@deftypefn {Function File} {@var{q} =} rot2q (@var{axis}, @var{angle})
174
Create unit quaternion @var{q} which describes a rotation of
175
@var{angle} radians about the vector @var{axis}. This function uses
176
the active convention where the vector @var{axis} is rotated by @var{angle}
177
radians. If the coordinate frame should be rotated by @var{angle}
178
radians, also called the passive convention, this is equivalent
179
to rotating the @var{axis} by @var{-angle} radians.
184
Vector @code{[x, y, z]} describing the axis of rotation.
186
Rotation angle in radians. The positive direction is
187
determined by the right-hand rule applied to @var{axis}.
193
Unit quaternion describing the rotation.
199
octave:1> axis = [0, 0, 1];
200
octave:2> angle = pi/4;
201
octave:3> q = rot2q (axis, angle)
202
q = 0.9239 + 0i + 0j + 0.3827k
203
octave:4> v = quaternion (1, 1, 0)
205
octave:5> vr = q * v * conj (q)
206
vr = 0 + 0i + 1.414j + 0k
212
@chapter Quaternion Methods
213
@section @@quaternion/abs
216
@deftypefn {Function File} {@var{qabs} =} abs (@var{q})
217
Modulus of a quaternion.
220
q = w + x*i + y*j + z*k
221
abs (q) = sqrt (w.^2 + x.^2 + y.^2 + z.^2)
224
@section @@quaternion/blkdiag
227
@deftypefn {Function File} {@var{q} =} blkdiag (@var{q1}, @var{q2}, @dots{})
228
Block-diagonal concatenation of quaternions.
230
@section @@quaternion/cat
233
@deftypefn {Function File} {@var{q} =} cat (@var{dim}, @var{q1}, @var{q2}, @dots{})
234
Concatenation of quaternions along dimension @var{dim}.
236
@section @@quaternion/columns
239
@deftypefn {Function File} {@var{nc} =} columns (@var{q})
240
Return number of columns @var{nc} of quaternion array @var{q}.
242
@section @@quaternion/conj
245
@deftypefn {Function File} {@var{q} =} conj (@var{q})
246
Return conjugate of a quaternion.
249
q = w + x*i + y*j + z*k
250
conj (q) = w - x*i - y*j - z*k
253
@section @@quaternion/diag
256
@deftypefn {Function File} {@var{q} =} diag (@var{v})
257
@deftypefnx {Function File} {@var{q} =} diag (@var{v}, @var{k})
258
Return a diagonal quaternion matrix with quaternion vector V on diagonal K.
259
The second argument is optional. If it is positive,
260
the vector is placed on the K-th super-diagonal.
261
If it is negative, it is placed on the -K-th sub-diagonal.
262
The default value of K is 0, and the vector is placed
263
on the main diagonal.
264
Given a matrix argument, instead of a vector, @command{diag}
265
extracts the @var{K}-th diagonal of the matrix.
267
@section @@quaternion/diff
270
@deftypefn {Function File} {@var{qdot} =} diff (@var{q}, @var{omega})
271
Derivative of a quaternion.
273
Let Q be a quaternion to transform a vector from a fixed frame to
274
a rotating frame. If the rotating frame is rotating about the
275
[x, y, z] axes at angular rates [wx, wy, wz], then the derivative
282
If the passive convention is used (rotate the frame, not the vector),
289
@section @@quaternion/exp
292
@deftypefn {Function File} {@var{qexp} =} exp (@var{q})
293
Exponential of a quaternion.
295
@section @@quaternion/inv
298
@deftypefn {Function File} {@var{qinv} =} inv (@var{q})
299
Return inverse of a quaternion.
301
@section @@quaternion/ispure
304
@deftypefn {Function File} {@var{flg} =} ispure (@var{q})
305
Return 1 if scalar part of quaternion is zero, otherwise return 0
307
@section @@quaternion/log
310
@deftypefn {Function File} {@var{qlog} =} log (@var{q})
311
Logarithmus naturalis of a quaternion.
313
@section @@quaternion/norm
316
@deftypefn {Function File} {@var{n} =} norm (@var{q})
317
Norm of a quaternion.
319
@section @@quaternion/rows
322
@deftypefn {Function File} {@var{nr} =} rows (@var{q})
323
Return number of rows @var{nr} of quaternion array @var{q}.
325
@section @@quaternion/size
328
@deftypefn {Function File} {@var{nvec} =} size (@var{q})
329
@deftypefnx {Function File} {@var{n} =} size (@var{q}, @var{dim})
330
@deftypefnx {Function File} {[@var{nx}, @var{ny}, @dots{}] =} size (@var{q})
331
Return size of quaternion arrays.
338
If given a second argument, @command{size} will return the size of the
339
corresponding dimension.
345
Row vector. The first element is the number of rows and the second
346
element the number of columns. If @var{q} is an n-dimensional array
347
of quaternions, the n-th element of @var{nvec} corresponds to the
348
size of the n-th dimension of @var{q}.
350
Scalar value. The size of the dimension @var{dim}.
356
Sizes of the 3rd to n-th dimensions.
359
@section @@quaternion/size_equal
362
@deftypefn {Function File} {@var{bool} =} size_equal (@var{a}, @var{b}, @dots{})
363
Return true if quaternions (and matrices) @var{a}, @var{b}, @dots{}
364
are of equal size and false otherwise.
366
@section @@quaternion/unit
369
@deftypefn {Function File} {@var{qn} =} unit (@var{q})
370
Normalize quaternion to length 1 (unit quaternion).
373
q = w + x*i + y*j + z*k
374
unit (q) = q ./ sqrt (w.^2 + x.^2 + y.^2 + z.^2)
377
@chapter Overloaded Quaternion Operators
378
@section @@quaternion/ctranspose
381
Conjugate transpose of a quaternion. Used by Octave for "q'".
382
@section @@quaternion/eq
385
Equal to operator for two quaternions. Used by Octave for "q1 == q2".
386
@section @@quaternion/horzcat
389
Horizontal concatenation of quaternions. Used by Octave for "[q1, q2]".
390
@section @@quaternion/ldivide
393
Element-wise left division for quaternions. Used by Octave for "q1 .\ q2".
394
@section @@quaternion/minus
397
Subtraction of two quaternions. Used by Octave for "q1 - q2".
398
@section @@quaternion/mldivide
401
Matrix left division for quaternions. Used by Octave for "q1 \ q2".
402
@section @@quaternion/mpower
405
Matrix power operator of quaternions. Used by Octave for "q^x".
406
@section @@quaternion/mrdivide
409
Matrix right division for quaternions. Used by Octave for "q1 / q2".
410
@section @@quaternion/mtimes
413
Matrix multiplication of two quaternions. Used by Octave for "q1 * q2".
414
@section @@quaternion/plus
417
Addition of two quaternions. Used by Octave for "q1 + q2".
418
@section @@quaternion/power
421
Power operator of quaternions. Used by Octave for "q.^x".
422
Exponent x can be scalar or of appropriate size.
423
@section @@quaternion/rdivide
426
Element-wise right division for quaternions. Used by Octave for "q1 ./ q2".
427
@section @@quaternion/subsasgn
430
Subscripted assignment for quaternions.
431
Used by Octave for "q.key = value".
432
@section @@quaternion/subsref
435
Subscripted reference for quaternions. Used by Octave for "q.w".
436
@section @@quaternion/times
439
Element-wise multiplication of two quaternions. Used by Octave for "q1 .* q2".
440
@section @@quaternion/transpose
443
Transpose of a quaternion. Used by Octave for "q.'".
444
@section @@quaternion/uminus
447
Unary minus of a quaternion. Used by Octave for "-q".
448
@section @@quaternion/uplus
451
Unary plus of a quaternion. Used by Octave for "+q".
452
@section @@quaternion/vertcat
455
Vertical concatenation of quaternions. Used by Octave for "[q1; q2]".