필터 지우기
필터 지우기

Is rotation matrix for rotating a vector can take any value of angle?

조회 수: 46 (최근 30일)
Aman
Aman 2024년 6월 2일
답변: Nipun 2024년 6월 11일
o2 = [0, 0, 0]; % Origin
ain = [1, 0, 0]; % Initial vector
input_axis = [0, 0, 1]; % Axis of rotation (z-axis)
theta = deg2rad(25); % Angle of rotation in radians
% Rotation matrix function
rot_matrix = @(axis, theta) cos(theta) * eye(3) + ...
sin(theta) * [0, -axis(3), axis(2); axis(3), 0, -axis(1); -axis(2), axis(1), 0] + ...
(1 - cos(theta)) * (axis' * axis);
% Compute the rotated vector
a_rotated = rot_matrix(input_axis, theta) * (ain - o2)' + o2';
% Transpose to row vector for display
a_rotated = a_rotated';
bin=[3,0,2];
o4=[3,0,-2];
output_axis=[1,0,0];
% Compute the rotated vector in terms of phi
syms phi;
rot_matrix_phi = rot_matrix(output_axis, phi);
bin_o4_rotated = rot_matrix_phi * (bin - o4)' ;
bin_o4_rotated = bin_o4_rotated'; % Transpose to row vector for display
% Display the symbolic result
disp('Rotated bin-o4 in terms of phi:');
% Display the result
disp(a_rotated)
disp(bin_o4_rotated);
o4o2=o4-o2;
disp(o4o2);
coupler=(o4o2+bin_o4_rotated-a_rotated);
display(coupler);
% Define the initial rotated components of the coupler
syms phi;
coupler = subs(coupler, conj(phi), phi);
%disp('Coupler vector without conjugate:');
disp(coupler);
% Parametric substitution
syms t;
cos_phi = (1 - t^2) / (1 + t^2);
sin_phi = 2 * t / (1 + t^2);
% Substitute parametric forms into coupler components
coupler_parametric = subs(coupler, [cos(phi), sin(phi)], [cos_phi, sin_phi]);
% Display the parametric coupler
disp('Parametric form of coupler:');
disp(coupler_parametric);
%after this stepit is unable to solve for theta more than 91 deg or less than -91 deg
syms targetvalue % it might be 3.5 ...
normsq = expand(sum(coupler_parametric.^2) - targetvalue^2);
normpoly = simplify(normsq*(t^2+1)^2);
vpa(expand(normpoly),4);
tsolve = solve(normpoly,t,'maxdegree',4,'returnconditions',true);
h=vpa(subs(tsolve.t,targetvalue,3.5));
%disp(h);
real_solutions = h(imag(h) == 0);
disp('Real roots:');
disp(real_solutions);
% Convert real values of t to angles using angle = 2 * atan(t)
angles_rad = 2 * atan(real_solutions);
angles_deg = rad2deg(angles_rad);
% Display angles in degrees
disp('Angles in degrees before adjustment:');
disp(angles_deg);
%please consider that if i take theta(in bold) more than 91 deg or less than -91 deg instead of 25 then it is not giving me the output(means angles_deg),is it the problem with my code or rotation matrix?
  댓글 수: 4
Aman
Aman 2024년 6월 3일
@Matt J sir i have attached the output of this code if i take theta equals 92 degrees.
it is unable to solve for values of t.
Thanks!!
Aman
Aman 2024년 6월 3일
편집: Aman 2024년 6월 3일
@VBBV Sir,I am saying that i want to change only value of theta greater than 91 deg,but it is unable to solve for values of t if targetvalue is 3.5.

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

답변 (1개)

Nipun
Nipun 2024년 6월 11일
Hi Aman,
I understand that you are experiencing issues with your MATLAB code when trying to solve for angles greater than 91 degrees or less than -91 degrees. The problem might be related to the parametric substitution and the solution of the polynomial equation.
Here's a revised version of your code, with some improvements to ensure it works for a wider range of angles:
% Given variables
o2 = [0, 0, 0];
ain = [1, 0, 0];
input_axis = [0, 0, 1];
theta = deg2rad(25);
bin = [3, 0, 2];
o4 = [3, 0, -2];
output_axis = [1, 0, 0];
% Rotation matrix function
rot_matrix = @(axis, theta) cos(theta) * eye(3) + ...
sin(theta) * [0, -axis(3), axis(2); axis(3), 0, -axis(1); -axis(2), axis(1), 0] + ...
(1 - cos(theta)) * (axis' * axis);
% Compute the rotated vector
a_rotated = rot_matrix(input_axis, theta) * (ain - o2)' + o2';
a_rotated = a_rotated';
% Compute the rotated vector in terms of phi
syms phi;
rot_matrix_phi = rot_matrix(output_axis, phi);
bin_o4_rotated = rot_matrix_phi * (bin - o4)';
bin_o4_rotated = bin_o4_rotated';
% Display the symbolic result
disp('Rotated bin-o4 in terms of phi:');
disp(a_rotated)
disp(bin_o4_rotated);
o4o2 = o4 - o2;
disp(o4o2);
coupler = (o4o2 + bin_o4_rotated - a_rotated);
disp(coupler);
% Define the initial rotated components of the coupler
coupler = subs(coupler, conj(phi), phi);
disp(coupler);
% Parametric substitution
syms t;
cos_phi = (1 - t^2) / (1 + t^2);
sin_phi = 2 * t / (1 + t^2);
% Substitute parametric forms into coupler components
coupler_parametric = subs(coupler, [cos(phi), sin(phi)], [cos_phi, sin_phi]);
disp('Parametric form of coupler:');
disp(coupler_parametric);
% Solve for target value
syms targetvalue;
normsq = expand(sum(coupler_parametric.^2) - targetvalue^2);
normpoly = simplify(normsq * (t^2 + 1)^2);
normpoly = vpa(expand(normpoly), 4);
tsolve = solve(normpoly, t, 'MaxDegree', 4, 'ReturnConditions', true);
h = vpa(subs(tsolve.t, targetvalue, 3.5));
real_solutions = h(imag(h) == 0);
disp('Real roots:');
disp(real_solutions);
% Convert real values of t to angles using angle = 2 * atan(t)
angles_rad = 2 * atan(real_solutions);
angles_deg = rad2deg(angles_rad);
disp('Angles in degrees before adjustment:');
disp(angles_deg);
For more details on rotation matrices in MATLAB, you can refer to this documentation link: https://www.mathworks.com/help/phased/ref/rotx.html
Hope this helps.
Regards,
Nipun

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by