angdiff doesn't work as documented

조회 수: 11 (최근 30일)
Eyal Itskovits
Eyal Itskovits 2016년 8월 31일
편집: Guillaume 2016년 8월 31일
Hello,
I'm using matlab 2015b. When used with a single variable, angdiff is documented to return the angular difference (smallest distance) between two adjacent angles.
Practically, it returns the distance of all the angles from zero. For example, this - angdiff(0:(pi/6):2*pi)
suppose to return [pi/6, pi/6 ... ] but it returns, [0, pi/6, 2*pi/6 ..]
Thank you, Eyal.

답변 (2개)

Guillaume
Guillaume 2016년 8월 31일
편집: Guillaume 2016년 8월 31일
I don't have the robotics toolbox, so can't check. If it does truly behave as you say then it is a bug you should reports to mathworks.
In the meantime, the function is trivial to implement:
function delta = nonbuggy_angdiff(alpha, beta)
validateattributes(alpha, {'numeric'}, {'vector', 'nonsparse'}, 1);
if nargin > 1
validateattributes(beta, {'numeric'}, {'vector', 'nonsparse', 'size', size(alpha)}, 2);
alpha = beta - alpha;
else
alpha = diff(alpha);
end
delta = mod(alpha + pi, 2*pi) - pi; %constrain to [-pi, pi[. will prefer -pi over +pi
delta(delta == -pi & alpha >= 0) = pi; %so force -pi to +pi (only when the original angle was positive)
end
edit: bugfix. There may still be bugs lurking about.
  댓글 수: 2
Thorsten
Thorsten 2016년 8월 31일
편집: Thorsten 2016년 8월 31일
This functions returns pi for angdiff(0,pi) and angdiff(pi, 0), which is wrong, or at least a bit strange.
And it does not work properly on arrays.
It return only a single pi if all values are pi:
angdiff([0 pi], [pi 0])
ans =
3.1416
and it gives inconsistent results if not all elements equal -pi:
angdiff([0 pi 0 ], [pi 0 0.1])
ans =
-3.1416 -3.1416 0.1000
because with single values angdiff(0,pi) and angdiff(pi,0) both return pi, not -pi.
And it does not work on some single matrices, as expected:
>> angdiff([0 pi 0])
ans =
3.1416
Should be pi, -pi.
Guillaume
Guillaume 2016년 8월 31일
The first issue was a bug. Now fixed.
As to what angle should be returned for a pi or -pi angle, I find it puzzling that the official angdiff returns both since they're the same mod 2pi.
In any case, that was trivial to adapt to, so now my function should behave the same as the official angdiff.
As said, I don't have the robotics toolbox to check.

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


Thorsten
Thorsten 2016년 8월 31일
Have a look which angdiff you use
which angdiff
it may be function different from the angdiff in the Robotics Toolbox.

카테고리

Help CenterFile Exchange에서 Coordinate Transformations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by