# quaternion

## Quaternion

Create a quaternion s <v1,v2,v3>, which is useful for representing 3D rotation.

### Syntax

• q = Quaternion( )
• q = Quaternion(Q1)
• q = Quaternion([s v1 v2 v3])
• q = Quaternion(s)
• q = Quaternion(V)
• q = Quaternion(theta, K)
• q = Quaternion(R)
• q = Quaternion(T)

### Input Arguments

• Q1 — a quaternion s <v1,v2,v3>
• [s v1 v2 v3] — a 1 x 4 vector representaion of quaternion
• s — a scalar part of quaternion
• V — a 1 x 3 vector part of quaternion
• theta — rotation angle (radian)
• K — a 1 x 3 vector representing axis of rotation
• R — 3 x 3 rotation matrix
• T — 4×4 homogeneous transformation matrix

### Output Arguments

• q — a quaternion s <v1,v2,v3>

### Description

A quaternion is a compact method of representing a 3D rotation that has computational advantages including speed and numerical robustness. A quaternion has 2 parts, a scalar s, and a vector v and is typically written: q = s <vx, vy, vz>

• q = Quaternion( ) creates an identity quaternion 1 <0, 0, 0>
• q = Quaternion(Q1) creates a copy of quaternion Q1
• q = Quaternion([s v1 v2 v3]) creates a quaternion from 1 x 4 vector representation
• q = Quaternion(s) creates a quaternion with scalar part s and zero vector part
• q = Quaternion(V) creates a quaternion 0 < V >
• q = Quaternion(theta, K) creates a unit quaternion representing a rotation of theta about vector K
• q = Quaternion(R) creates a unit quaternion corresponding to a rotation matrix R. If R (3x3xN) is a sequence then q (Nx1) is a vector of quaternions corresponding to the elements of R.
• q = Quaternion(T) creates a unit quaternion corresponding to a homogeneous transform T. If T (4x4xN) is a sequence then q (Nx1) is a vector of quaternions corresponding to the elements of T.

### Examples

 -->q = Quaternion([2 1 -1 4]) q = s: 2 v: [1,-1,4]   -->q = Quaternion(pi/4,[1 -1 1]) q = s: 0.9238795 v: [0.2209424,-0.2209424,0.2209424]   -->T = trotx(pi/2); -->q = Quaternion(T) q = s: 0.7071068 v: [0.7071068,0,0]