필터 지우기
필터 지우기

Quaternions Computation Time too long

조회 수: 4 (최근 30일)
Ozan Anli
Ozan Anli 2022년 11월 22일
편집: Jan 2022년 11월 22일
Hello,
we have written a script to illustrate the rotation of objects in space. This is calculated once using rotation matrices and once using quaternions. We have also tracked the computation time and noticed that the computation for the quaternions take longer than for the rotation matrices. According to the theory, the calculation of quaternions should work faster than for rotation matrices. Can you explain why this is not the case here.
Thank you very much in advance.
  댓글 수: 1
Jan
Jan 2022년 11월 22일
The relevant part of the code:
x = [0;1;0]; % Vector to rotate
theta = 33; % Angle
n = 999; % Number of rotations
Rx = rotx(theta);
tic;
for i = 1:n
y = Rx * x;
x = y;
end
toc;
Elapsed time is 0.005929 seconds.
y.'
ans = 1×3
0 -0.8910 -0.4540
% Quaternion
x = [0,1,0];
v = [1,0,0];
v_dach = quaternion(0, v(1), v(2), v(3));
theta = deg2rad(theta);
q = cos(theta/2) + sin(theta/2)*v_dach;
tic;
for i = 1:n
y = rotatepoint(q,x);
x = y;
end
toc;
Elapsed time is 0.071161 seconds.
y
y = 1×3
0 -0.8910 -0.4540

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

답변 (1개)

Jan
Jan 2022년 11월 22일
편집: Jan 2022년 11월 22일
While the multiplication with the rotation matrix calls an optimzed BLAS library directly, rotatepoint is a function, which calls the functions prepRotate for a normalization and compact after the multiplication. Calling functions have a certain overhead. Look into prepRotate to see, that there are further checks of the inputs and function calls.
The normalization matters, if the vectors have different scalings, e.g. x = [0, 1e180, 0]. Of course considering such exceptions costs runtime. The profiler helps you to examine, where the time is spent:
profile on
% run your code
profile report
"Faster in theory" is not really meaningful, if a function is applied to tiny input data. Maybe the theoretical advantage matters, if your input data has millions of points.

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by