Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nearest Neighbours using Quaternions

Given a quaternion value, I would like to find its nearest neighbour in a set of quaternions. To do this, I clearly need a way to compare the "distance" between two quaternions. What distance representation is needed for such a comparison and how is it computed?

Thanks,

Josh

like image 873
Josh Avatar asked Feb 07 '11 01:02

Josh


1 Answers

This is an old question, but it seemed to need a little more answer. If the quaternions are unit-length quaternions being used to represent rotations, then Euclidean distance will give some funny results because quaternions provide 2x redundant representation of rotation space; i.e., a quaternion and its negation represent the same orientation. In this case, the correct distance metric is the angle between the quaternions, constrained to fall within [0,pi/2]:

theta = acos(q1.w*q2.w + q1.x*q2.x + q1.y*q2.y + q1.z*q2.z);
if (theta>pi/2) theta = pi - theta;
like image 51
JCooper Avatar answered Sep 22 '22 15:09

JCooper