Filter löschen
Filter löschen

angle2dcm: How to reference direction cosine matrix output?

7 Ansichten (letzte 30 Tage)
Kurt
Kurt am 29 Mär. 2023
Bearbeitet: Kurt am 3 Apr. 2023
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 Kommentare
Kurt
Kurt am 30 Mär. 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 am 31 Mär. 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)]?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

James Tursa
James Tursa am 31 Mär. 2023
Bearbeitet: James Tursa am 31 Mär. 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,:);

Weitere Antworten (0)

Kategorien

Mehr zu Cartesian Coordinate System Conversion finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by