From direction cosine matrix to Cardan angles - Two different Matlab codes, different results
$begingroup$
I have two Matlab codes to get the Cardan angles (ZXY sequence) starting from a given direction cosine matrix (dcm), but the results are different. Why?
The dcm is:
dcm = [0.5972 -0.7833 0.1729;
0.7990 0.5987 -0.0553;
-0.0592 0.1719 0.9832];
First code (alpha=angle around x, beta=angle around y, gamma=angle around z):
[gamma, alpha, beta] = dcm2angle(dcm,'ZXY');
% Result:
% -0.9277 -0.0553 -0.1741
Second code:
if abs(dcm(3,2)) ~= 1
alpha = asin(dcm(3,2));
%
if dcm(3,3) >= 0
beta = asin(-dcm(3,1)/cos(alpha));
else
beta = pi - asin(-dcm(3,1)/cos(alpha));
end
%
if dcm(2,2) >= 0
gamma = asin(-dcm(1,2)/cos(alpha));
else
gamma = pi - asin(-dcm(1,2)/cos(alpha));
end
end
% Result:
% 0.9192 0.1728 0.0601
The dcm for the sequence ZXY in terms of sin and cos is:
Thank you so much for your willingness.
matrices matlab education rotations classical-mechanics
$endgroup$
add a comment |
$begingroup$
I have two Matlab codes to get the Cardan angles (ZXY sequence) starting from a given direction cosine matrix (dcm), but the results are different. Why?
The dcm is:
dcm = [0.5972 -0.7833 0.1729;
0.7990 0.5987 -0.0553;
-0.0592 0.1719 0.9832];
First code (alpha=angle around x, beta=angle around y, gamma=angle around z):
[gamma, alpha, beta] = dcm2angle(dcm,'ZXY');
% Result:
% -0.9277 -0.0553 -0.1741
Second code:
if abs(dcm(3,2)) ~= 1
alpha = asin(dcm(3,2));
%
if dcm(3,3) >= 0
beta = asin(-dcm(3,1)/cos(alpha));
else
beta = pi - asin(-dcm(3,1)/cos(alpha));
end
%
if dcm(2,2) >= 0
gamma = asin(-dcm(1,2)/cos(alpha));
else
gamma = pi - asin(-dcm(1,2)/cos(alpha));
end
end
% Result:
% 0.9192 0.1728 0.0601
The dcm for the sequence ZXY in terms of sin and cos is:
Thank you so much for your willingness.
matrices matlab education rotations classical-mechanics
$endgroup$
$begingroup$
Just to check, apply also both methods on the transpose of thedcm
matrix.
$endgroup$
– LutzL
Dec 23 '18 at 8:44
$begingroup$
You can get the beta and gamma values with less lines usingbeta = atan2(-dcm(3,1), dcm(3,3)
andgamma = atan2(-dcm(1,2), dcm(2,2))
.
$endgroup$
– LutzL
Dec 23 '18 at 12:19
$begingroup$
Hello @LutzL, I have to use the above code because my professor said that I have to implement the analitic procedure in my book. Anyway thank you for your suggestion and sorry for the delay of my reply.
$endgroup$
– Gennaro Arguzzi
Dec 24 '18 at 23:55
add a comment |
$begingroup$
I have two Matlab codes to get the Cardan angles (ZXY sequence) starting from a given direction cosine matrix (dcm), but the results are different. Why?
The dcm is:
dcm = [0.5972 -0.7833 0.1729;
0.7990 0.5987 -0.0553;
-0.0592 0.1719 0.9832];
First code (alpha=angle around x, beta=angle around y, gamma=angle around z):
[gamma, alpha, beta] = dcm2angle(dcm,'ZXY');
% Result:
% -0.9277 -0.0553 -0.1741
Second code:
if abs(dcm(3,2)) ~= 1
alpha = asin(dcm(3,2));
%
if dcm(3,3) >= 0
beta = asin(-dcm(3,1)/cos(alpha));
else
beta = pi - asin(-dcm(3,1)/cos(alpha));
end
%
if dcm(2,2) >= 0
gamma = asin(-dcm(1,2)/cos(alpha));
else
gamma = pi - asin(-dcm(1,2)/cos(alpha));
end
end
% Result:
% 0.9192 0.1728 0.0601
The dcm for the sequence ZXY in terms of sin and cos is:
Thank you so much for your willingness.
matrices matlab education rotations classical-mechanics
$endgroup$
I have two Matlab codes to get the Cardan angles (ZXY sequence) starting from a given direction cosine matrix (dcm), but the results are different. Why?
The dcm is:
dcm = [0.5972 -0.7833 0.1729;
0.7990 0.5987 -0.0553;
-0.0592 0.1719 0.9832];
First code (alpha=angle around x, beta=angle around y, gamma=angle around z):
[gamma, alpha, beta] = dcm2angle(dcm,'ZXY');
% Result:
% -0.9277 -0.0553 -0.1741
Second code:
if abs(dcm(3,2)) ~= 1
alpha = asin(dcm(3,2));
%
if dcm(3,3) >= 0
beta = asin(-dcm(3,1)/cos(alpha));
else
beta = pi - asin(-dcm(3,1)/cos(alpha));
end
%
if dcm(2,2) >= 0
gamma = asin(-dcm(1,2)/cos(alpha));
else
gamma = pi - asin(-dcm(1,2)/cos(alpha));
end
end
% Result:
% 0.9192 0.1728 0.0601
The dcm for the sequence ZXY in terms of sin and cos is:
Thank you so much for your willingness.
matrices matlab education rotations classical-mechanics
matrices matlab education rotations classical-mechanics
edited Dec 23 '18 at 8:05
Gennaro Arguzzi
asked Dec 22 '18 at 17:20
Gennaro ArguzziGennaro Arguzzi
336314
336314
$begingroup$
Just to check, apply also both methods on the transpose of thedcm
matrix.
$endgroup$
– LutzL
Dec 23 '18 at 8:44
$begingroup$
You can get the beta and gamma values with less lines usingbeta = atan2(-dcm(3,1), dcm(3,3)
andgamma = atan2(-dcm(1,2), dcm(2,2))
.
$endgroup$
– LutzL
Dec 23 '18 at 12:19
$begingroup$
Hello @LutzL, I have to use the above code because my professor said that I have to implement the analitic procedure in my book. Anyway thank you for your suggestion and sorry for the delay of my reply.
$endgroup$
– Gennaro Arguzzi
Dec 24 '18 at 23:55
add a comment |
$begingroup$
Just to check, apply also both methods on the transpose of thedcm
matrix.
$endgroup$
– LutzL
Dec 23 '18 at 8:44
$begingroup$
You can get the beta and gamma values with less lines usingbeta = atan2(-dcm(3,1), dcm(3,3)
andgamma = atan2(-dcm(1,2), dcm(2,2))
.
$endgroup$
– LutzL
Dec 23 '18 at 12:19
$begingroup$
Hello @LutzL, I have to use the above code because my professor said that I have to implement the analitic procedure in my book. Anyway thank you for your suggestion and sorry for the delay of my reply.
$endgroup$
– Gennaro Arguzzi
Dec 24 '18 at 23:55
$begingroup$
Just to check, apply also both methods on the transpose of the
dcm
matrix.$endgroup$
– LutzL
Dec 23 '18 at 8:44
$begingroup$
Just to check, apply also both methods on the transpose of the
dcm
matrix.$endgroup$
– LutzL
Dec 23 '18 at 8:44
$begingroup$
You can get the beta and gamma values with less lines using
beta = atan2(-dcm(3,1), dcm(3,3)
and gamma = atan2(-dcm(1,2), dcm(2,2))
.$endgroup$
– LutzL
Dec 23 '18 at 12:19
$begingroup$
You can get the beta and gamma values with less lines using
beta = atan2(-dcm(3,1), dcm(3,3)
and gamma = atan2(-dcm(1,2), dcm(2,2))
.$endgroup$
– LutzL
Dec 23 '18 at 12:19
$begingroup$
Hello @LutzL, I have to use the above code because my professor said that I have to implement the analitic procedure in my book. Anyway thank you for your suggestion and sorry for the delay of my reply.
$endgroup$
– Gennaro Arguzzi
Dec 24 '18 at 23:55
$begingroup$
Hello @LutzL, I have to use the above code because my professor said that I have to implement the analitic procedure in my book. Anyway thank you for your suggestion and sorry for the delay of my reply.
$endgroup$
– Gennaro Arguzzi
Dec 24 '18 at 23:55
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3049658%2ffrom-direction-cosine-matrix-to-cardan-angles-two-different-matlab-codes-diff%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3049658%2ffrom-direction-cosine-matrix-to-cardan-angles-two-different-matlab-codes-diff%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Just to check, apply also both methods on the transpose of the
dcm
matrix.$endgroup$
– LutzL
Dec 23 '18 at 8:44
$begingroup$
You can get the beta and gamma values with less lines using
beta = atan2(-dcm(3,1), dcm(3,3)
andgamma = atan2(-dcm(1,2), dcm(2,2))
.$endgroup$
– LutzL
Dec 23 '18 at 12:19
$begingroup$
Hello @LutzL, I have to use the above code because my professor said that I have to implement the analitic procedure in my book. Anyway thank you for your suggestion and sorry for the delay of my reply.
$endgroup$
– Gennaro Arguzzi
Dec 24 '18 at 23:55