Unfortunately, in line four it tells me that I am not passing enough input arguments. I don't quite understand how to fix the error? The code seems to be correct for me. I actually converted the code from python to matlab because in matlab I need the function.
Thanks for your help!
Code:
function e = angle_axis(T,Td)
e = [];
e(1:3) = Td(1:3,end)-T(1:3,end); % -> Mistake
R = Td(1:3, 1:3) * T(1:3, 1:3).';
li = [R(2, 1) - R(1, 2), R(0, 2) - R(2, 0), R(1, 0) - R(0, 1)];
if any(li)
% diagonal matrix case
if trace(R) > 0
% (1,1,1) case
a = zeros(3,0);
else
a = pi/2*(diag(R)+1);
end
else
ln = norm(li);
a = atan2(ln, trace(R)-1)*li/ln;
end
e(3:1) = a;
end

4 commentaires

Torsten
Torsten le 29 Déc 2021
In MATLAB, array indexing starts with 1, i.e. R(0,y) and R(x,0) errors.
Christian Vogel
Christian Vogel le 29 Déc 2021
Thanks for the note! I have corrected the mistake, but I still have the same problem....
Torsten
Torsten le 29 Déc 2021
Modifié(e) : Torsten le 29 Déc 2021
Then post your revised code together with the call to "angle_axis" and the error message you get.
And allocating zeros(3,0) also does not make much sense - you get an empty matrix.
Christian Vogel
Christian Vogel le 29 Déc 2021
Thanks for your help!

Connectez-vous pour commenter.

 Réponse acceptée

KSSV
KSSV le 29 Déc 2021

0 votes

The error is clear. You are trying to run the function by hitting the run button/ F5 key. You need to provide the inputs to the function and then call the function.
T = define your value ;
Td = define your value ;
e = angle_axis(T,Td) % now call the function

1 commentaire

Christian Vogel
Christian Vogel le 29 Déc 2021
Now I have following mistake, after I provide the inputs for the function (refer png)

Connectez-vous pour commenter.

Plus de réponses (1)

Christian Vogel
Christian Vogel le 29 Déc 2021

0 votes

That is the "translated" Matlab code:
function e = angle_axis(T,Td)
e = [];
e(1:3) = Td(1:3,end)-T(1:3,end);
R = Td(1:3, 1:3) * T(1:3, 1:3).';
li = [R(3, 2) - R(2, 3), R(1, 3) - R(3, 1), R(2, 1) - R(1, 2)];
if any(li)
% diagonal matrix case
if trace(R) > 0
% (1,1,1) case
a = zeros(3,1);
else
a = pi/2*(diag(R)+1);
end
else
ln = norm(li);
a = atan2(ln, trace(R)-1)*li/ln;
end
e(3:1) = a;
end
That is the python code:
def _angle_axis(T, Td):
e = np.empty(6)
e[:3] = Td[:3, -1] - T[:3, -1]
R = Td[:3, :3] @ T[:3, :3].T
li = np.array([R[2, 1] - R[1, 2], R[0, 2] - R[2, 0], R[1, 0] - R[0, 1]])
if base.iszerovec(li):
# diagonal matrix case
if np.trace(R) > 0:
# (1,1,1) case
a = np.zeros((3,))
else:
a = np.pi / 2 * (np.diag(R) + 1)
else:
# non-diagonal matrix case
ln = base.norm(li)
a = math.atan2(ln, np.trace(R) - 1) * li / ln
e[3:] = a
return e
And when I run the Matlab code, I get following issue (please refer png data)

3 commentaires

Torsten
Torsten le 29 Déc 2021
Where is the call to "angle_axis" ?
You can not just run the function - it expects matrices T and Td. If you don't supply them, it has "not enough input arguments".
Christian Vogel
Christian Vogel le 29 Déc 2021
Sorry my fault! That was stupid of me.
I have following issue, when I run the function (refer png)
Torsten
Torsten le 29 Déc 2021
Modifié(e) : Torsten le 29 Déc 2021
In the last line of angle_axis, use
e(1:3) = a
instead of
e(3:1) = a
or whatever is senseful in this context (e(3:1) is empty).

Connectez-vous pour commenter.

Catégories

Produits

Version

R2020a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by