I am using the following code to open a .csv file, index columns of interest (euler rotations around x, y, z axes) as single column arrays, and then sequentially order these as a 3 x n matrix:
%Imports geometric camera parameters from phtosynth output .csv in the
%current directory and orders columns as seperate 1 x n matrices
if exist('PARAMETERS_0.csv', 'file') == 2 disp('file found') [PX PY PZ RX RY RZ] = csvimport('PARAMETERS_0.csv', 'columns', {' PositionX', ' PositionY', ' PositionY', ' RotationX', ' RotationY', ' RotationZ'});else disp('camera parameters input file not found')end % Sequentially indexes RX RY RZ into a 3 x n matrix where columns are euler
% angles around x y z axes
for i=1:length(RX) MRV(:,i)=[RX(i);RY(i);RZ(i)]; end
The resulting 3 x n matrix looks like this:
[0.5053 0.5300 0.3820 -0.1594 -0.1289 -0.1107 -1.1684 1.4532 1.4258 1.1240 1.2185 1.2424 1.2131 0.9390 1.4532 1.4258 1.1240 1.2185 1.2424 1.2131 0.9390]
Where individual columns represent euler rotations around x, y z axis (in descending order), describing the orientation of a camera:
e.g.
POV1 = 0.5053 1.4532 1.4532
My problem is that I need to use the euler rotations represented as column vectors in the matrix (MRV) as inputs to calculate a 3 x 3 rotation matrix for each camera position (POV1,..,POVn). The functions to achieve this in the command console would be as follows (example using column 1):
Rx1 = [1 0 0; 0 cosd(MPV(1,1)) -sind(MPV(1,1)); 0 sind(MPV(1,1)) cosd(MPV(1,1))];Ry1 = [cosd(MPV(2,1)) 0 sind(MPV(2,1)); 0 1 0; -sind(MPV(2,1)) 0 cosd(MPV(2,1))];Rz1 = [cosd(MPV(3,1)) -sind(MPV(3,1)) 0; sind(MPV(3,1)) cosd(MPV(3,1)) 0; 0 0 1];RM1 = Rz1*Ry1*Rx1
This function would need to be applied sequentially to each column to give an output rotation matrix of the form:
r11 r12 r13r21 r22 r23r31 r32 r33
I know that the code needed would be a for loop of some description but am a bit stuck on the nature of the syntax needed. Any help would be greatly appreciated. Note that I need also to concatenate this rotation matrix with a column vector from an equivalent 3 x n matrix to MRV (x y z position) and a single row array (0 0 0 1) to produce a 4 x 4 matrix (homogeneous coordinates) of the form:
r11 r12 r13 xr21 r22 r23 yr31 r32 r33 z0 0 0 1
So any solution would have to be compatible with next stage in the analysis
Best Answer