Borrar filtros
Borrar filtros

angle2dcm: How to reference direction cosine matrix output?

7 visualizaciones (últimos 30 días)
Kurt
Kurt el 29 de Mzo. de 2023
Editada: Kurt el 3 de Abr. de 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 comentarios
Kurt
Kurt el 30 de Mzo. de 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 el 31 de Mzo. de 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)]?

Iniciar sesión para comentar.

Respuesta aceptada

James Tursa
James Tursa el 31 de Mzo. de 2023
Editada: James Tursa el 31 de Mzo. de 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,:);

Más respuestas (0)

Categorías

Más información sobre Cartesian Coordinate System Conversion en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by