Here’s my starting set of vectors representing a local coordinate frame:
Starting point
Using some arbitrary rotation matrix, I rotate them in 3D:
Standard visual outcome after rotation by R
However, I’d like to keep the RGB vectors visually fixed and rotate the camera viewpoint such that the resulting image shows the world coordinate system rotated relative to the local coordinate frame:
Desired visual outcome after rotation by R
How would I do that programatically, using the rotation matrix (and thus being able to find Euler angles, quaternions, or an axis-angle representation, if necessary)?
1
First, assign a variable for the axis handle:
h = gca;
Then, you can manipulate the View property (azimuth and elevation).
For example, to get a flat view of X,Y axes, set:
h.View = [0 90]
If this is not enough, you can also control the cameraPosition property.
Refer also to the following documentation:
https://www.mathworks.com/help/matlab/ref/matlab.graphics.axis.axes-properties.html
https://www.mathworks.com/help/matlab/creating_plots/defining-scenes-with-camera-graphics.html
5
The hgtranform() API can be used to transform a graphics object. It can rotate, scale and translate graphics objects, more detailed discussion on the allowed and disallowed operations can be found here. Here is an example:
s = surf(peaks(20));
h = hgtransform();
set(s, 'parent', h);
h.Matrix = makehgtform("xrotate", pi/2);
This should rotate the surface plot by Pi/2 radians about the Z- axis. You can control the axis and angle of rotation by modifying the inputs to makehgtform().
1