Plotting quaternion in Matlab using "engine.h" from c++

2.3k views Asked by At

I have an algorithm in C++ that uses Kalman Filter. Somewhere in the code a predict a Quaternion q' and then I update the Quaternion with Kalman Filter q.

I want to plot two graphics in Matlab with the evolution of the predicted quaternion and the corrected(updated) quaternion so I am using "engine.h" library to send quaternion info to Matlab during processing (actually what I send is a 4x1 matrix).

So my question is: What is the best way to plot a quaternion in Matlab so I can visually extract information? Is it maybe better to plot the angles separately?

2

There are 2 answers

0
Carlos Cachalote On BEST ANSWER

I think a good option is sending the quaternion as a vector to MATLAB, using C++ MATLAB engine

[qx qy qz qw]

Then, in MATLAB environment you can use a toolbox for translating to Euler Angles, which is a common visual option.

For adding a path of a toolbox in matlab engine:

addpath(genpath('C:\Program Files (x86)\MATLAB\R2010a\toolbox\SpinCalc'));

With spincalc toolbox, converting would be something like this:

Angles=SpinCalc('QtoEA321',Quaternion,0,0);
0
Andrey Rubshtein On

Well, assuming that the question is "How to visualize in a nice way a 4D space", I can think of a few options:

  • Show multiple slices of the space, that is for (x,y,z,t) -> (x,y), (y,z),etc..
  • Show (x,y) as scatter plot and encode the information of z in color, t in size of dot. For that you can use the scatter command :

SCATTER(X,Y,S,C) displays colored circles at the locations specified by the vectors X and Y (which must be the same size).

If your question was "How to visualize in a nice way quarternions, check this out