Effacer les filtres
Effacer les filtres

angle2dcm: How to reference direction cosine matrix output?

7 vues (au cours des 30 derniers jours)
Kurt
Kurt le 29 Mar 2023
Modifié(e) : Kurt le 3 Avr 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 commentaires
Kurt
Kurt le 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 le 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)]?

Connectez-vous pour commenter.

Réponse acceptée

James Tursa
James Tursa le 31 Mar 2023
Modifié(e) : James Tursa le 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,:);
  1 commentaire
Kurt
Kurt le 31 Mar 2023
Modifié(e) : Kurt le 3 Avr 2023
That worked. Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Cartesian Coordinate System Conversion dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by