angdiff doesn't work as documented
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposte (2)
Guillaume
il 31 Ago 2016
Modificato: Guillaume
il 31 Ago 2016
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 Commenti
Thorsten
il 31 Ago 2016
Modificato: Thorsten
il 31 Ago 2016
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
il 31 Ago 2016
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
il 31 Ago 2016
Have a look which angdiff you use
which angdiff
it may be function different from the angdiff in the Robotics Toolbox.
0 Commenti
Vedere anche
Categorie
Scopri di più su Coordinate Transformations in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!