shubhtuls / ViewpointsAndKeypoints

Code Release for "Viewpoints and Keypoints" CVPR 2015.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

angle2dcm

siddharthm28 opened this issue · comments

Hi, I have the MATLAB Total Academic Headcount license from my university and it doesn't have the aerospace toolbox as part of it. I wrote up a short script which I believe does what you want. I'd appreciate it if you can confirm it please.
Thanks !

function dcm = angle2dcm(r1, r2, r3, seq)
% my implementation of the angle2dcm code
% Usage in code: R = angle2dcm(euler(3), euler(2)-pi/2, -euler(1),'ZXZ'); 
seq = lower(seq);
angles = [r1 r2 r3];
dcm = eye(3);
for i = 1:length(seq)
	switch seq(i)
		case 'x'
			dcm = dcm * Rx(angles(i));
		case 'y'
			dcm = dcm * Ry(angles(i));
		case 'z'
			dcm = dcm * Rz(angles(i));
	end
end

function R = Rx(theta)
% rotation about x-axis by angle theta
R = [1 0 0; 0 cos(theta) -sin(theta); 0 sin(theta) cos(theta)];

function R = Ry(theta)
% rotation about y-axis by angle theta
R = [cos(theta) 0 sin(theta); 0 1 0; -sin(theta) 0 cos(theta)];

function R = Rz(theta)
% rotation about z-axis by angle theta
R = [cos(theta) -sin(theta) 0; sin(theta) cos(theta) 0; 0 0 1];

I think the rotation this code returns is the transpose of the MATLAB implementation's result. This is because the rotations matrices Rx, Ry, Rz defined above are transposed compared to MATLAB convention and the matrices are multiplied as R1 X R2 X R3 (whereas in MATLAB it is R3 X R2 X R1).
See here for a reference implementation.

Ahh... I was assuming the implicit 3D points are column-wise: 3 X N. But if the points are row-wise: N X 3.. with the rotation being applied as Y = X * R, you are correct. I'll make the change accordingly. Closing the issue now, thanks !