# quaternion projection

Posted Wednesday, 4 May, 2011 - 14:37 by NeoSniperkiller inHello,

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.

-- QUATERNIONS ==> PROJECTION ON PLANE ==> POINTS IN PLANE

| 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)?

Thanks!

## Comments

## Re: quaternion projection

Try this:

## Re: quaternion projection

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.

## Re: quaternion projection

Oops :)

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

## Re: quaternion projection

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

## Re: quaternion projection

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

## Re: quaternion projection

owkey I'll try to gather the necessary info for you

should I post it here or pm it to you?

## Re: quaternion projection

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

## Re: quaternion projection

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?

## Re: quaternion projection

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:

## Re: quaternion projection

thank you for supplying the formula, but this is still not quite the correct 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?