Search code examples
c#quaternions

Get xyz coordinates from starting point, quaternion and moved distance


In my case I have a starting coordinate x,y,z, an orientation in Quaternion and I know the moved distance.

Basically I would like to know the x',y',z' after applying the transformation and the forward movement. So I am trying to move a point in 3D using quaternion. I guess it should be just a simple calculation but for some reason I cannot find the solution that easily.

In previously I converted the Quaternion to Euler angles and used them to calculate the x',y',z'. Unfortunately because of the Gimbal lock this solution is not suitable for me anymore.

I have found a few example for example this one in python and here's an other in C#, but I still did not get the formula of them as they are discussing the rotation instead of the movement it self, the C# example just changes the middle point of the cube and then it redraws it with the rotation.


Solution

  • Why reinvent the wheel ? This kind of operation is best handled via matrixes - and C# has even support for it.

    // PresentationCore.dll 
    using System.Windows.Media.Media3D;
    
    Matrix3D matrix = Matrix3D.Identity;
    matrix.Translate(new Vector3D(x, y, z));
    matrix.Rotate(quaterion);
    var newPoint = matrix.Transform(point);