anti - 11 months ago 54

C# Question

I need to offset streaming quaternion data by a specific amount. To do this I plan to get the difference between the 2, then offset the first by the second.

I am having trouble finding the difference between the 2.

Using this converter.

I am running this code:

`public void convertQuat180()`

{

Quaternion q = new Quaternion(0.65328f, 0.2706f, 0.65328f, -0.2706f); //45,180,0

Quaternion q180 = new Quaternion(0.70711f, 0, 0.70711f, 0); // 0,90,0

Quaternion result = q180 * Quaternion.Inverse(q);

Console.WriteLine(result);

}

I would expect

`result`

`(euler) diff = 45, 90 , 0`

But instead i get:

`135,-180,0`

Where am i going wrong here?

Answer Source

What you want is a transformation of coordinate systems. You have a rotation measured by the sensor `RS`

and a rotation of the camera `RC`

. Both are related by a constant (let's call it) offset `RO`

:

```
RS = RC * RO
```

Or alternatively

```
RC = RS * RO^-1
```

During your calibration procedure, you acquire `RS`

and `RC`

. Then, you can calculate the offset as:

```
RO = RC^-1 * RS
RO^-1 = RS^-1 * RC
```

Just calculate the one that you will use more often (probably `RO^-1`

because you want to get the camera rotation from the sensor rotation).