我在MATLAB中遇到了一些非常奇怪的東西,我無法弄清楚。MATLAB解決()不能解決特定值的三角矩陣
我有兩組我想要找到歐拉角的物體座標。我設置了旋轉矩陣R
和符號卡丹角矩陣R_cardan
來解決角度。對於第一組,我可以簡單地做solve(R==R_cardan)
,但是當我使用第二組時,它不起作用。返回的解決方案是空的。
這可能是什麼原因造成的?這裏是測試代碼。
clc;clear;close all;
%% For some reason R2 does not want to give a solution
% Find rotation matrix to transform from origin to local reference frame
ex = [ 0.768 0.024 0.640].';
ey = [-0.424 0.768 0.480].';
ez = [-0.480 -0.640 0.600].';
ex2 = [ 0.612372 0.353553 -0.707107].';
ey2 = [0.280330 0.739199 0.612372].';
ez2 = [0.739199 -0.573223 0.353553].';
R = eye(3)*[ex ey ez]
R2 = eye(3)*[ex2 ey2 ez2]
% Symbolic variables
syms beta alpha gamma
% Set up rotatin matrices
R_alpha = [cos(alpha) -sin(alpha) 0; sin(alpha) cos(alpha) 0; 0 0 1]
R_beta = [cos(beta) 0 sin(beta); 0 1 0; -sin(beta) 0 cos(beta)]
R_gamma = [1 0 0; 0 cos(gamma) -sin(gamma); 0 sin(gamma) cos(gamma)]
% Find symbolic rotation matrix
R_cardan = R_alpha*R_beta*R_gamma
[alpha, beta, gamma] = find_angles(R,R_cardan)
[alpha, beta, gamma] = find_angles(R2,R_cardan) %fails because solution is empty
function [alpha, beta, gamma] = find_angles(R,R_cardan)
% Solve for the angles
sol = solve(R == R_cardan);
alpha = double(sol.alpha(1));
beta = double(sol.beta(1));
gamma = double(sol.gamma(1));
end
我目前的解決方案是手動計算角度是好的,但我對上述方法有什麼問題感興趣。
非常感謝您。這是一個非常好但很複雜的解決方案。然而,瞭解解決問題的特殊方式絕對值得。 – Ortix92