Asked by Patrícia Falcão
on 23 Aug 2018

How do we calculate angle between 2 quaternions? For example, what is the angle between x = ( 0.968, 0.008, -0.008, 0.252) and y = (0.382, 0.605, 0.413, 0.563)? How can I do it in matlab?

Answer by James Tursa
on 23 Aug 2018

Edited by James Tursa
on 23 Aug 2018

Assuming these represent attitude rotations from one coordinate frame to another, if you are simply asking what is the minimum rotation to take you from one quaternion to the other, you simply multiply one quaternion by the conjugate of the other and then pick off the rotation angle of the resulting quaternion.

But we really need to know what these quaternions represent, and what angle you are trying to recover, before we know what you want.

E.g., suppose x and y represent ECI->BODY rotation quaternions, and you want to know the minimum rotation angle that would take you from the x BODY position to the y BODY position. Then you could do this:

>> x = [ 0.968, 0.008, -0.008, 0.252]; x = x/norm(x); % ECI->BODY1

>> y = [ 0.382, 0.605, 0.413, 0.563]; y = y/norm(y); % ECI->BODY2

>> z = quatmultiply(quatconj(x),y) % BODY1->BODY2

z =

0.5132 0.6911 0.2549 0.4405

>> a = 2*acosd(z(4)) % min angle rotation from BODY1 to BODY2

a =

127.7227

But, again, these calculations are dependent on how I have the quaternions defined. Your specific case may be different.

Silas Waxter
on 17 Aug 2019

James Tursa
on 19 Aug 2019

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Pawel Jastrzebski (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/415936-angle-between-2-quaternions#comment_602613

## Patrícia Falcão (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/415936-angle-between-2-quaternions#comment_602618

## Patrícia Falcão (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/415936-angle-between-2-quaternions#comment_602619

## Rik (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/415936-angle-between-2-quaternions#comment_602754

Sign in to comment.