Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab 3D view matrix

Tags:

view

matlab

3d

Let A be MATLAB's 4x4 view matrix, obtained from the view function by:

A = view;

A(1:3,1:3) should correspond to rotation and scaling,
A(1:3,4) should correspond to translation, and
A(4,:) should simply be [0 0 0 1].

When setting the camera parameters to the following simple scenario:

camproj('orthographic')
set(gca, 'CameraPosition', [0,0,0])
set(gca, 'CameraTarget', [0,0,1])
set(gca, 'CameraUpVector', [0,1,1])

I get that A = view is:

-1 0 0  0.5
 0 1 0 -0.5
 0 0 1 -0.5
 0 0 0    1

Now I can't figure our where the 0.5's are coming from. Note that I set the camera position to [0,0,0] so there should be no translation.

Another peculiarity, setting the camera position to [0,0,10] by:

set(gca, 'CameraPosition', [0,0,10])

results in the A:=view matrix becoming

1 0  0 -0.5
0 1  0 -0.5
0 0 -1  5.5
0 0  0    1

So I've noticed the -0.5 has changed to 5.5 in A(3,4) and this somehow has to do with 5 = 10 / 2.
That is, changing the camera position to [0,0,a] changes the view matrix at A(3,4) by roughly a / 2.

This is... weird? Peculiar? Odd?

Update: Yet another pecularity is that the determinant of A(1:3,1:3) is -1 although for a rotation matrix it should be 1. When it's -1 it means that it's not only rotation but also reflection. Why would we need reflection?

like image 781
Ofer Avatar asked May 30 '12 20:05

Ofer


1 Answers

Try the same in Matlab 2013a .. you will find the results matching the expectation ...I don't know which version of Matlab you are using .. but it is certainly fixed in version 8.1

like image 134
waleed shawki Avatar answered Oct 23 '22 16:10

waleed shawki