How to vary angles at constant rate in a kinematics problem?

5 次查看(过去 30 天)
o2 = [0, 0, 0]; % Origin
ain = [26,0,0]; % Initial vector
input_axis = [0,1,0]; % Axis of rotation (z-axis)
theta1 = deg2rad(157.5); % 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, theta1) * (ain' - o2') + o2';
% Transpose to row vector for display
a_rotated = a_rotated';
a_final=a_rotated;
bin=[29.5,46,0];
o4=[13.5,46,0];
output_axis=[0,1,0];
theta2= deg2rad(105);
b1_rotated = rot_matrix(output_axis, theta2) * (bin' - o4') + o4';
b1_final=b1_rotated';
u3=[0,0,1];
c1=[125,0,0];
% Compute the rotated vector in terms of phi
syms phi;
rot_matrix_phi = rot_matrix(u3, phi);
c1_afinal_rotated = rot_matrix_phi * (c1 - a_final)'+a_final' ;
c1_afinal_rotated = c1_afinal_rotated'; % Transpose to row vector for display
o4o2=o4-o2;
%disp(o4o2);
coupler=(c1_afinal_rotated-b1_final);
% 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);
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, 106));
%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);
phi=double(angles_rad(1));
p=double(angles_deg(1));
c1_position = double(rot_matrix(u3, phi) * (c1' - a_final') + a_final');
p=(c1_position'-a_final)';
disp(p');
disp(p(2)/norm(c1_position'-a_final));
final_angle_phi=acosd(p(2)/norm(c1_position'-a_final)); % angle with y axis
disp(final_angle_phi) ;
disp(norm(c1_position'-b1_final));
disp(norm(a_rotated-o2));
%% in this code i want to change theta1 at rate of 90deg/sec and theta2 at rate of 60 deg/sec varying from 0 to 360 deg and want to calculate corresponding value of final_angle_phi with the y axis
%please help someone
  3 个评论
Aman
Aman 2024-6-6
@Deepak Gupta yes sir,it will be and i am taking c1,c2 equal to 0.
can you please tell how can i write a loop for varying theta1 and theta2 at at given rates to find corresponding final_angle_phi??
Deepak Gupta
Deepak Gupta 2024-6-6
You should not need to write a for loop. Matlab works on vectors and matrices. So just define time as a vector and calculate corresponding theta values. i.e.
t = 0:0.01:10;
theta1 = 90 * t;
theta2 = 60 * t;

请先登录,再进行评论。

采纳的回答

Aquatris
Aquatris 2024-6-6
编辑:Aquatris 2024-6-6
For loops are easy to understand but as mentioned in comments, once you understand the logic you should vectorize it. The basic idea is as follow:
t = 0:0.01:4; % 4 seconds since 90*4 = 360, meaning theta1 goes from 0 to 360
theta1_vec = deg2rad(90*t); % array with theta1 angles at 0 sec upto 4 sec
theta2_vec = deg2rad(60*t); % array with theta2 angles at 0 sec upto 4 sec
for i = 1:length(t)
theta1 = theta1_vec(i);
theta2 = theta2_vec(i);
%%====rest of your code======%%
% store values you want as array
final_angle_phi(i)=acosd(p(2)/norm(c1_position'-a_final));
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by