rt_quaternion - construct/clone a quaternion object[view code]
This function is the constructor for a quaternion object. The quaternion object has type quat.
The first form returns a new object with the same value as its argument.
The second form initializes the quaternion to a rotation of theta radians about the vector v.
The third and the fourth forms set the quaternion to a rotation equivalent to the given rotation matrix R, or to the rotation submatrix of the given homogeneous transform T, respectively.
The fifth form sets the four quaternion elements directly.
All forms, except the last, return a unit quaternion, i.e. one whose magnitude is unity.
Since Scilab does not support the concept of public class, variables methods have been written to allow quaternion object parameters to be referenced (r) or assigned (a) as given by the following table:
| Method | Operation | Returns | Type |
| quat.d | r | the vector formed by stacking of quaternion elements | 4-element vector |
| quat.s | r | the scalar component of the quaternion | scalar |
| quat.v | r | the vector part of the quaternion | 3-element vector |
| quat.t | r | the equivalent homogeneous transform matrix | 4-by-4 matrix |
| quat.r | r | the equivalent orthonormal rotation matrix | 3-by-3 matrix |
In Scilab variable display and operators may be defined for new objects using Scilab-coded functions. The following is a list of all overloaded operators for the new Scilab object, the quaternion:
In Scilab some basic primitive functions may be overloaded for new data types. The following is a list of all overloaded functions for the new Scilab object, the quaternion:
// set the four quaternion elements directly
rt_quaternion([1, 1, 0, 0]),
// a quaternion obtained from a rotation matrix
rt_quaternion(rt_tr2rot(rt_rotx(1))),
// The following example shows how to use the public class variables
// methods
T = rt_rotx(0.2), // A rotation of 0.2rads about the
// X-axis (homogeneous transform)
q1 = rt_quaternion(T), // set q1 from a homog. transform
q1.r, // get the equivalent orthonormal
// rotation matrix
q1.t, // returns T
q1.s, // the scalar component
q1.v, // the vector part
q1.d, // the 4-element vector [q1.s, q1.v]
q1.s = 1, // error! all methods can be
q1.v = [1, 0, 0], // only referenced
// Playing with overloaded operators and functions...
q2 = rt_quaternion(rt_roty(0.3)), // another quaternion
q1*q2, // quaternion product
q1*q1, // square quaternion
q1^2,
q1 * inv(q1), // invert quaternion
q1/q1,
q1/q2, // quaternion division
q1 * q2^(-1),
// Get the type of a quaternion object
typeof(q1) == "quat", // returns %T (true)
typeof(q1) == "quaternion", // returns %F (false)
At the moment vectors or arrays of quaternions are not supported. You can however use Scilab lists to hold a number of quaternions.
Corke, P.I. "A Robotics Toolbox for MATLAB", IEEE Robotics and Automation Magazine, Volume 3(1), March 1996, pp. 24-32
K. Shoemake, "Animating rotation with quaternion curves", in Proceedings of ACM SIGGRAPH, (San Francisco), pp. 245-254, The Singer Company, Link Flight Simulator Division, 1985.