angle2dcm: How to reference direction cosine matrix output?

11 views (last 30 days)
I have seen lots of discussion on how to call angle2dcm, but almost none on how to use it to transform the coordinates of an object.
Here is my sample code. I create an ellipse in 3D and apply pitch, roll and yaw angles to it. How do I pry the results out of angle2dcm?
function tilt_ellipse()
xc = 50;
yc = 50;
zc = 50;
a = 25;
b = 50;
m = 1000;
x = zeros(m,1);
y = zeros(m,1);
z = zeros(m,1);
dtor = 0.01745 % degrees to radians
theta = linspace(0,2*pi,m);
for k = 1:m % define ellipse
x(k) = a * cos(theta(k));
y(k) = b * sin(theta(k));
end
pitch = input('Enter the pitch in degrees');
roll = input('Enter the roll in degrees');
yaw = input('Enter the yaw in degrees');
dcm = angle2dcm(pitch * dtor, roll * dtor, yaw * dtor, "ZYX"); % is this the correct rotation order?
xr = ? % how do I get the vector rotations?
yr = ?
zr = ?
plot3(xr+xc, yr+yc, zr+zc);
grid on;
hold on;
axis equal;
end
This should work for any object that I apply the transformations to (vector, ellipse, cone, etc.)
  2 Comments
Kurt
Kurt on 30 Mar 2023
This code is an extension of the 2D example referenced here, which uses a cosine matrix for transformation. I'm looking for the generalized 3D solution using angle2dcm().
Kurt
Kurt on 31 Mar 2023
Hint: If pitch, roll and yaw are zero, I get the identity matrix:
[1 0 0
0 1 0
0 0 1]
Is this a clue as to where I find my results? i.e., m[(1,1), (2,2), (3,3)]?

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 31 Mar 2023
Edited: James Tursa on 31 Mar 2023
Does this do what you want:
x = zeros(1,m); % reorder these to row vectors
y = zeros(1,m);
z = zeros(1,m);
:
xyz = [x;y;z]; % matrix with column vectors of (x,y,z) points
xyzr = dcm * xyz; % rotate them
xr = xyzr(1,:); % pick off x,y,z components
yr = xyzr(2,:);
zr = xyzr(3,:);

More Answers (0)

Categories

Find more on Cartesian Coordinate System Conversion in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!