what's the code inside angle2dcm?
34 views (last 30 days)
Show older comments
I saw angle2dcm on Mathworks but don't know how scalars of x,y,z or vectors of x,y,z become matrix after using angle2dcm.
Can anyone explain the code embedded?
Thanks very much.
0 Comments
Accepted Answer
Mathieu NOE
on 27 Apr 2022
hello
here you are
notice that there are some issues / questions about orientation convention with this function
function [dcm] = angle2dcm(r,seq)
% dcm = angle2dcm(r1,r2,r3,seq)
% builds euler angle rotation matrix
%
% r = [r1 r2 r3]
% seq = 'ZYX' (default)
% 'ZXZ'
% dcm = direction cosine matrix
if nargin == 1
seq = 'ZYX';
end
switch seq
case 'ZYX'
dcm = Tx(r(3))*Ty(r(2))*Tz(r(1));
case 'ZXZ'
dcm = Tz(r(3))*Tx(r(2))*Tz(r(1));
end
function A = Tx(a)
A = [1 0 0;0 cosd(a) sind(a);0 -sind(a) cosd(a)];
function A = Ty(a)
A = [cosd(a) 0 -sind(a);0 1 0;sind(a) 0 cosd(a)];
function A = Tz(a)
A = [cosd(a) sind(a) 0;-sind(a) cosd(a) 0;0 0 1];
More Answers (1)
Jan
on 27 Apr 2022
While I cannot find the code of angle2dcm , the equivalent function eul2rotm is useful for the explanation also. It produces the transposed matrix compared to angle2dcm.
See:
edit eul2rotm
3 angles define the attitude of a coordinate system. The "dcm" matrix (direction cosine matrix) contains the 3 unit vectors of the base of a rotated coordinate system.
See Also
Categories
Find more on Axes Transformations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!