# dcm2quat

Convert direction cosine matrix to quaternion

## Syntax

```q = dcm2quat(n) ```

## Description

`q = dcm2quat(n)` calculates the quaternion, `q`, for a given direction cosine matrix, `n`. Input `n` is a 3-by-3-by-`m` matrix of orthogonal direction cosine matrices. The direction cosine matrix performs the coordinate transformation of a vector in inertial axes to a vector in body axes. `q` returns an `m`-by-4 matrix containing `m` quaternions. `q` has its scalar number as the first column.

This function applies only to direction cosine matrices that are orthogonal with determinant +1.

## Examples

Determine the quaternion from direction cosine matrix:

```dcm = [0 1 0; 1 0 0; 0 0 1]; q = dcm2quat(dcm) q = 0.7071 0 0 0```

Determine the quaternions from multiple direction cosine matrices:

```dcm = [ 0 1 0; 1 0 0; 0 0 1]; dcm(:,:,2) = [ 0.4330 0.2500 -0.8660; ... 0.1768 0.9186 0.3536; ... 0.8839 -0.3062 0.3536]; q = dcm2quat(dcm) q = 0.7071 0 0 0 0.8224 0.2006 0.5320 0.0223```