Search code examples
matlabmatlab-figure

MATLAB plot3 left handed coordinate system


I would like to display some data in Matlab using plot3. This data makes the most sense in the left handed coordinate system.

enter image description here

However, MATLAB's 3D plot coordinate system is oriented with Z up which is inconsistent with the way the data is recorded - making visualization confusing. I understand that Matlab is also using a left handed coordinate system, except that it's rotated 90deg clockwise about the x-axis.

enter image description here

I've tried using the camup command which gets kind of close to what I want, but as soon as the plot is rotated in the GUI, the camup is thrown away and the plot reverts back to the above convention.

I would prefer not to rotate my data 90deg clockwise about the x-axis because it will introduce another level of ambiguity when it comes time for analysis and debugging.

EDIT: I think this sequence of instructions gets close.

enter image description here

set(gca, 'YDir', 'reverse');
camup([0 1 0]);
xlabel('X (mm)');
ylabel('Y (mm)');
zlabel('Z (mm)');

Solution

  • You can plot a left handed coordinate system by reversing the direction of any one of the axes. This is controlled by the XDir, YDir, or ZDir properties of the axes.

    surf(peaks)
    set(gca, 'ZDir', 'reverse')
    xlabel('x')
    ylabel('y')
    zlabel('z')
    

    enter image description here