NeoSniperkiller's picture

quaternion projection


I'm trying to make a Dynamic Time Warping algorithm for usage with Quaternions.
In order for making the cost function to work, it has to calculate a specific cost between 2 Quaternions.

I've developped a cost function to make it work, but it requires the projection of a quaternion on an plane/axis.

| Q1 measured value ==> (1,0,0) * Q1 ==> P1'
| Q2 pattern value ==> (1,0,0) * Q2 ==> P2'

cost = SQRT( Abs(P1.x - P2.x) + Abs(P1.y - P2.y) + Abs(P1.z - P2.z) )

Now i'm currently encountering the trouble of making that projection part to work with OpenTK's math library.

Can anybody help me with this or guide me to the function (if there is one available yet)?



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Try this:

using System; // System.Math provides most common math functions
using OpenTK; // OpenTK provides quaternions
class Test
    public static void Main()
        var cost = Math.Sqrt(Math.Abs(P1.X - P2.X) + Math.Abs(P1.Y - P2.Y) + Math.Abs(P1.Z - P2.Z));
NeoSniperkiller's picture

umm you posted nothing but the final cost function, which I already have :-)

Where I'm stuck at, is the part that projects both the quaternions onto one plane.
So that it is possible to calculate the distances between them.

the Fiddler's picture

Oops :)

There's nothing like that built-in, but it should be possible to implement given existing functions.

NeoSniperkiller's picture

so heh can you help me with it? :-)

I've never worked with quaternions before, so the OpenTK functions are like a mystery for me

the Fiddler's picture

If you can provide the math for quaternion-to-plane projection, I can help you with the translation to OpenTK code. :)

NeoSniperkiller's picture

owkey I'll try to gather the necessary info for you
should I post it here or pm it to you?

the Fiddler's picture

Better to post here so that others can join in the discussion.

NeoSniperkiller's picture

I'm very sorry, but after a meeting with my thesis mentor we've discovered that the question was formulated in a wrong way.
below is the correct way:

How is it possible, with OpenTK, to calculate the distance between two Quaternions?

the Fiddler's picture

According to :


s 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.

In C#, this would be:

Math.Sqrt(Math.Pow(q1.X - q2.X, 2) +  Math.Pow(q1.Y - q2.Y, 2) + Math.Pow(q1.Z - q2.Z, 2))
NeoSniperkiller's picture

thank you for supplying the formula, but this is still not quite the correct one

  1. Dynamic Time Warping uses only 1-dimensional timeseries, a quaternion has 4 dimensions. So the distance formule you provided is not the suitable one for DTW.
  2. Multi-Dimensional DTW uses all the dimensions at once, so then your distance formula is the good one

DTW (1 dimensional) <-> MDDTW (multi-dimensional)
x    <->   x,y,z

that's why i tried to project a quaternion to one plane, but now i'm thinking of using a point cloud in order to do this
anybody knows a better way?