Search code examples
distancequaternionsnearest-neighbor

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


Solution

  • Is your quaternion just a point in 3D space with an orientation?

    Then the distance between two quaternions x1,y1,z1,w1 and x2,y2,x2,w2 is given by:

    distance = sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2), assuming that the w component is used for orientation. I.e. this is the same as the distance between two 3D points.

    Is your quaternion a point in 4D space?

    Then the distance between them is given by:

    distance = sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2 + (w1-w2)^2).

    Which is just the extension to 4D space. This euclidean distance formula works in any number of dimensions.