Nearest neighbors using quaternions

Given the importance of quaternion, I would like to find my closest neighbor in the quaternion set. To do this, I clearly need a way to compare the "distance" between the two quaternions. What distance is required for such a comparison and how is it calculated?

Thanks,

Josh

+7
source share
4 answers

Is your quaternion just a point in three-dimensional orientation space?

Then the distance between the two quaternions x1,y1,z1,w1 and x2,y2,x2,w2 is determined as follows:

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

Is your quaternion a point in 4D space?

Then the distance between them is determined as follows:

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

This is just an extension to 4D space. This Euclidean distance formula works in any number of dimensions.

+5
source

This is an old question, but it seems like he needs a little more answer. If quaternions are unit length quaternions used to represent rotations, then the Euclidean distance will give some ridiculous results, since quaternions provide a 2x redundant representation of the rotation space; those. quaternion and its negation represent the same orientation. In this case, the correct distance metric is the angle between the quaternions, limited by the 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; 
+9
source

It really depends on what you use your quaternions for. A simple measure of distance would be the absolute magnitude of their difference.

If x = a + b i + cj + dk y = e + f i + gj + hk

what the Euclidean distance will be

  |xy| = sqrt( (ae)² + (bf)² + (cg)² + (dh)² ) 
+1
source

If “distance” means the shortest rotation of the arc between two orientations, then a simple Euclidean distance is normal (L2 or norm2).

since the angle between the orientations can be written as

 theta = acos(q1.w*q2.w + q1.x*q2.x + q1.y*q2.y + q1.z*q2.z); 

The larger L2, the greater the distance.

NOTE: all quaternions should be reset before request if you provide a product with a negative point. Than you can use the usual combination of KNN to speed up your queries.

0
source

All Articles