How to have a coordinate system that moves with the object
이전 댓글 표시
I am trying to rotate an object (airplane) on a 2D figure but I am having problems. The way I have my code now the roll works fine no matter the orientation of the object. Yaw and pitch rotate about a fixed axis. If I change the order of multiplication on the rotation matrix, I can get another direction to work as desired but the other 2 don't work as needed. I had tried putting in some code to change the order based on what parameter was changed and that works as far as the axii being "movable" but if I for example change the roll and then go to change the pitch, the object jumps back to some random orientation and from then on, the pitch will work. When I go to change the yaw, it will jump to some random position but then the yaw works correctly.
I did some searching and I think the answer is to use quaterions or some intrinsic rotation. I am lost on doing either of these but maybe someone can get me headed in the right direction. The big thing with quaterions is that my object matrix is m-by-3 but it needs to be m-by-4 in order to do any operations on it.
Below is a snippet of my code. I retyped from a computer without internet access so hopefully I didn't leave something out.
%define vertices (just a plate right now)
vertices = [-5 -5 0; -5 5 0; 5 5 0; 5 -5 0];
pitch = 15;
roll = 45;
yaw = 30;
vertices = rotateVertices(vertices, pitch, roll, yaw);
%run function to plot new vertices
%begin rotate function
function vertices = rotateVertices(vertices, pitch, roll, yaw)
pitch = pi/180*pitch;
roll = pi/180*pitch;
yaw = pi/180*pitch;
%rotation matrix
Rx = [1 0 0; 0 cos(pitch) -sin(pitch); 0 sin(pitch) cos(pitch)];
Ry = [cos(roll) 0 sin(roll); 0 1 0; -sin(roll) 0 cos(roll)];
Rz = [cos(yaw) -sin(yaw) 0; sin(yaw) cos(yaw) 0; 0 0 1];
Rt = Rz*Rx*Ry;
vertices = Rt*vertices;
%end function
답변 (1개)
Mischa Kim
2013년 12월 20일
편집: Mischa Kim
2013년 12월 20일
0 개 추천
Typically, for aircraft dynamics you would use a 3-2-1 (or z-y-x) rotation sequence for yaw-pitch-roll (your are using a y-x-z sequence in the example above). Also, careful with the correct location of negative signs in the individual rotation matrices.
댓글 수: 2
David
2013년 12월 20일
Mischa Kim
2013년 12월 20일
편집: Mischa Kim
2013년 12월 20일
Please check the other post I am referring to. It shows the rotation matrices with the correct negative signs and the overall rotation matrix I believe you need for your application (z-y-x).
If you are only rotating vectors (or vertices, like in your case) the rotation matrix is the way to go. If on the other hand you would like to visualize the rotation of an object in a VR world you need to convert the rotation matrix into the corresponding rotation vector and angle (called Euler axis and angle).
The other thing I just noticed in your code is the conversion to rad where you use the pitch for all three angles.
카테고리
도움말 센터 및 File Exchange에서 Polar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!