필터 지우기
필터 지우기

angle2dcm: How to reference direction cosine matrix output?

조회 수: 7 (최근 30일)
Kurt
Kurt 2023년 3월 29일
편집: Kurt 2023년 4월 3일
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
Kurt
Kurt 2023년 3월 30일
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 2023년 3월 31일
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)]?

댓글을 달려면 로그인하십시오.

채택된 답변

James Tursa
James Tursa 2023년 3월 31일
편집: James Tursa 2023년 3월 31일
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,:);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cartesian Coordinate System Conversion에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by