M-File Help: Quaternion | View code for Quaternion |
Quaternion class
A quaternion is 4-element mathematical object comprising a scalar s, and a vector v and is typically written: q = s <<vx, vy, vz>>.
A quaternion of unit length can be used to represent 3D orientation and is implemented by the subclass UnitQuaternion.
Quaternion | general constructor |
Quaternion.pure | pure quaternion |
display | print in human readable form |
inv | inverse |
conj | conjugate |
norm | norm, or length |
unit | unitized quaternion |
inner | inner product |
char | convert to string |
double | quaternion elements as 4-vector |
matrix | quaternion as a 4x4 matrix |
q*q2 | quaternion (Hamilton) product |
s*q | elementwise multiplication of quaternion by scalar |
q/q2 | q*q2.inv |
q^n | q to power n (integer only) |
q+q2 | elementwise sum of quaternion elements |
q-q2 | elementwise difference of quaternion elements |
q1==q2 | test for quaternion equality |
q1~=q2 | test for quaternion inequalityq = rx*ry*rz; |
s | real part |
v | vector part |
Construct a quaternion object
Q = Quaternion is a zero quaternion
Q = Quaternion([S V1 V2 V3]) is a quaternion formed by specifying directly its 4 elements
q = Quaternion(s, v) is a quaternion formed from the scalar s and vector part v (1x3)
Convert to string
s = Q.char() is a compact string representation of the quaternion's value as a 4-tuple. If Q is a vector then s has one line per element.
Conjugate of a quaternion
qi = Q.conj() is a quaternion object representing the conjugate of Q.
Display quaternion
Q.display() displays a compact string representation of the quaternion's value as a 4-tuple. If Q is a vector then S has one line per element.
Convert a quaternion to a 4-element vector
v = Q.double() is a row vector (1x4) comprising the quaternion elements, scalar then vector. If Q is a vector (1xN) of Quaternion objects then v is a matrix (Nx4) with rows corresponding to the Quaternion elements.
elements [s vx vy vz].
Test quaternion equality
Q1==Q2 is true if the quaternions Q1 and Q2 are equal.
Quaternion inner product
v = Q1.inner(q2) is the inner (dot) product of two vectors (1x4), comprising the elements of Q1 and q2 respectively.
Invert a quaternion
qi = Q.inv() is a quaternion object representing the inverse of Q.
Test quaternion element equality
ISEQUAL(q1,q2) is true if the quaternions q1 and q2 are equal.
Matrix representation of Quaternion
m = Q.matrix() is a matrix (4x4) representation of the Quaternion Q.
Quaternion, or Hamilton, multiplication can be implemented as a matrix-vector product, where the column-vector is the elements of a second quaternion:
matrix(Q1) * double(Q2)'
Quaternion.double, Quaternion.mtimes
Subtract quaternions
Q1-Q2 is a Quaternion formed from the element-wise difference of quaternion elements.
Q1-V is a Quaternion formed from the element-wise difference of Q1 and the vector V (1x4).
Raise quaternion to integer power
QˆN is the Quaternion Q raised to the integer power N.
Quaternion quotient.
Q1/Q2 | is a quaternion formed by Hamilton product of Q1 and inv(Q2). |
Q/S | is the element-wise division of quaternion elements by the scalar S. |
Quaternion.mtimes, Quaternion.mpower, Quaternion.plus, Quaternion.minus
Multiply a quaternion object
Q1*Q2 | is a quaternion formed by the Hamilton product of two quaternions. |
Q*S | is the element-wise multiplication of quaternion elements by the scalar S. |
S*Q | is the element-wise multiplication of quaternion elements by the scalar S. |
Quaternion.mrdivide, Quaternion.mpower
Test quaternion inequality
Q1 ~= Q2 is true if the quaternions Q1 and Q2 are not equal.
Construct a new quaternion
qn = Q.new() constructs a new Quaternion object of the same type as Q.
qn = Q.new([S V1 V2 V3]) as above but specified directly by its 4 elements.
qn = Q.new(s, v) as above but specified directly by the scalar s and vector part v (1x3)
Quaternion magnitude
qn = q.norm(q) is the scalar norm or magnitude of the quaternion q.
Quaternion.inner, Quaternion.unit
Add quaternions
Q1+Q2 is a Quaternion formed from the element-wise sum of quaternion elements.
Q1+V is a Quaternion formed from the element-wise sum of Q1 and the vector V (1x4).
Construct a pure quaternion
q = Quaternion.pure(v) is a pure quaternion formed from the vector v (1x3) and has a zero scalar part.
Set scalar component
Q.s = S sets the scalar part of the Quaternion object to S.
Set vector component
Q.v = V sets the vector part of the Quaternion object to V (1x3).
Unitize a quaternion
qu = Q.unit() is a UnitQuaternion object representing the same orientation as Q.
Quaternion.norm, UnitQuaternion
© 1990-2014 Peter Corke.