필터 지우기
필터 지우기

can someone explain how i would compute this code

조회 수: 3 (최근 30일)
lateef
lateef 2023년 7월 25일
댓글: James Tursa 2023년 7월 31일
% SO FAR THIS IS THE CODE IVE COMPUTED IM NOT SURE WHERE TO CONTINUE OR IF
% CODE CORRECT SO FAR
u1 = [1; 2; 3];
a1 = 45;
u2 = [0; 1; 0];
a2 = 30;
function qmul(u1, a1, u2, a2)
% Convert angles from degrees to radians
a1_rad = deg2rad(a1);
a2_rad = deg2rad(a2);
% Normalize the Euler axes
u1 = u1 / norm(u1);
u2 = u2 / norm(u2);
% Compute quaternions q1 and q2
epsilon1 = u1 * sin(a1_rad / 2);
eta1 = cos(a1_rad / 2);
q1 = [epsilon1; eta1];
epsilon2 = u2 * sin(a2_rad / 2);
eta2 = cos(a2_rad / 2);
q2 = [epsilon2; eta2];
% Compute q3 = q1 * q2 using quaternion multiplication
epsilon3 = cross(epsilon1, epsilon2) + eta1 * epsilon2 + eta2 * epsilon1;
eta3 = eta1 * eta2 - dot(epsilon1, epsilon2);
q3 = [epsilon3; eta3];
% Compute Q(q1) matrix
I = eye(3);
S_epsilon1 = [0, -epsilon1(3), epsilon1(2);
epsilon1(3), 0, -epsilon1(1);
-epsilon1(2), epsilon1(1), 0];
Q_q1 = eta1 * I + S_epsilon1 * epsilon1;
% Compute q3 = Q(q1) * q2 using matrix-vector multiplication
q3_matrix = Q_q1 * q2;
% Compute the rotation matrix R(q3)
R_q3 = (eta3 - norm(epsilon3)^2) * I + 2 * epsilon3 * epsilon3' - 2 * eta3 * S(epsilon3);
% Display results
fprintf('Quaternion q1: [%f, %f, %f, %f]\n', q1);
fprintf('Quaternion q2: [%f, %f, %f, %f]\n', q2);
fprintf('Quaternion q3 (quaternion multiplication): [%f, %f, %f, %f]\n', q3);
fprintf('Quaternion q3 (matrix-vector multiplication): [%f, %f, %f, %f]\n', q3_matrix);
fprintf('Matrix Q(q1):\n');
disp(Q_q1);
fprintf('Rotation matrix R(q3):\n');
disp(R_q3);
end
  댓글 수: 1
James Tursa
James Tursa 2023년 7월 31일
What exactly are you asking us to help you with? If you want to verify your quaternion multiplication and conversion to rotation matrix code, why not simply compare to results obtained from calling MATLAB functions for this? Keep in mind that MATLAB quaternion functions are in scalar-vector order, whereas your code is in vector-scalar order.

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

답변 (1개)

Image Analyst
Image Analyst 2023년 7월 25일
Your function qmul does not compute q1q2, or the rotation matrix Rq3, or print anything out to the command window. Fix those things and then enter in the same sample values they gave you and see if you get the same results as they do.
To learn other fundamental concepts, invest 2 hours of your time here:
  댓글 수: 1
Image Analyst
Image Analyst 2023년 7월 25일
By the way, what is the status of our other outstanding question here:
You never commented on it or accepted it. We don't like just tossing answers out into a black hole never to hear anything ever again.

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

카테고리

Help CenterFile Exchange에서 Quaternion Math에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by