The code for coupler curve of crank slider mechanism is not producing a curve on the graph, but is only showing the mechanism. There is no animation.
3 次查看(过去 30 天)
显示 更早的评论
%% Section 3 :Plotting and Animation
%-------------------------------------------------------------------------
%Plotting of slider curve and Coupler Extendion Coordinates
hold on;
title('Slider Coupler Curve Plotting')
xlim([-80,160]); ylim([-80,150])
% Coordinates of Slider Mechanism Link
% A B C E
Cx=[0 a*cos(T(i)) a*cos(T(i))+b*cos(Bita(i)) a*cos(T(i))+e*cos(ar-Bita(i))];
Cy=[0 a*sin(T(i)) e1 a*sin(T(i))+e*sin(ar-Bita(i))];
%% Mechanism Plotting
%
crank=line([Cx(1) Cx(2)],[Cy(1) Cy(2)],'color','r','linewidth',5);%link 1
coupler=line([Cx(2) Cx(3)],[Cy(2) Cy(3)],'color','g','linewidth',5);%link 2
eline=line([Cx(2) Cx(4)],[Cy(2) Cy(4)],'color','g','linewidth',3);
eoline=line([Cx(3) Cx(4)],[Cy(3) Cy(4)],'color','g','linewidth',3);%link e joint
Slider1=line([Cx(3)+sx Cx(3)+sx],[Cy(3)+sy Cy(3)-sy],'color','k','linewidth',1);
Slider3=line([Cx(3)-sx Cx(3)-sx],[Cy(3)+sy Cy(3)-sy],'color','k','linewidth',1);
plot(X,Y,'b','Linewidth',1); plot(XX,YY,'b','Linewidth',1)
Trace= viscircles([X(i) Y(i)],1,'Color','k');
A= viscircles([Cx(1) Cy(1)],2,'Color','k'); B= viscircles([Cx(2) Cy(2)],1,'Color','k');
C= viscircles([Cx(3) Cy(3)],1,'Color','k'); E= viscircles([Cx(4) Cy(4)],1,'Color','k');
%Animation of Plotting by Deleting the previous plotting
pause(0.005);delete(crank);delete(coupler);delete(eline)
delete(eoline);delete(Trace);delete(B);delete(C);delete(A);
delete(E);delete(Slider1);delete(Slider3);
end
%% Back to Initial Position
crank=line([Cx(1) Cx(2)],[Cy(1) Cy(2)],'color','r','linewidth',5);%link 1
coupler=line([Cx(2) Cx(3)],[Cy(2) Cy(3)],'color','g','linewidth',5);%link 2
eline=line([Cx(2) Cx(4)],[Cy(2) Cy(4)],'color','g','linewidth',3);
eoline=line([Cx(4) Cx(3)],[Cy(4) Cy(3)],'color','g','linewidth',3);
A= viscircles([Cx(1) Cy(1)],1,'Color','k'); B= viscircles([Cx(2) Cy(2)],1,'Color','k');
C= viscircles([Cx(3) Cy(3)],1,'Color','k'); E= viscircles([Cx(4) Cy(4)],1,'Color','k');
Slider1=line([Cx(3)+sx Cx(3)+sx],[Cy(3)+sy Cy(3)-sy],'color','k','linewidth',1);
Slider3=line([Cx(3)-sx Cx(3)-sx],[Cy(3)+sy Cy(3)-sy],'color','k','linewidth',1);
Crank_Radius=a
Slide_Distance= max(XX)-min(XX)
0 个评论
回答(1 个)
Abhishek Chakram
2024-2-8
Hi Triambakeshwar Malladi,
It appears that you want to add animation for the coupler curve of crank slider mechanism. Here is a complete MATLAB code example for the same:
% Define the mechanism parameters
a = 5; % Length of the crank
b = 10; % Length of the connecting rod
e = 7; % Length of the coupler
e1 = 5; % Offset of the slider
ar = pi/6; % Angle of the coupler from the connecting rod
sx = 1; % Half-width of the slider
sy = 2; % Half-height of the slider
% Define the simulation parameters
numSteps = 100; % Number of simulation steps
T = linspace(0, 2*pi, numSteps); % Crank angle range from 0 to 2*pi
Bita = asin(a/b * sin(T)); % Angle of the connecting rod
% Initialize arrays to store coupler curve points
X = zeros(1, numSteps);
Y = zeros(1, numSteps);
% Calculate coupler curve points
for i = 1:numSteps
X(i) = a*cos(T(i)) + e*cos(ar - Bita(i));
Y(i) = a*sin(T(i)) + e*sin(ar - Bita(i));
end
% Create a figure for the animation
figure;
hold on;
title('Slider-Crank Mechanism with Coupler Curve');
xlim([-a-b-e, a+b+e]);
ylim([-a-b-e, a+b+e]);
xlabel('X');
ylabel('Y');
grid on;
% Animation loop
for i = 1:numSteps
% Coordinates of Slider Mechanism Link
Cx = [0, a*cos(T(i)), a*cos(T(i)) + b*cos(Bita(i)), X(i)];
Cy = [0, a*sin(T(i)), e1, Y(i)];
% Mechanism Plotting
crank = line([Cx(1), Cx(2)], [Cy(1), Cy(2)], 'color', 'r', 'linewidth', 5); % Crank
coupler = line([Cx(2), Cx(4)], [Cy(2), Cy(4)], 'color', 'g', 'linewidth', 5); % Coupler
connecting_rod = line([Cx(2), Cx(3)], [Cy(2), Cy(3)], 'color', 'b', 'linewidth', 5); % Connecting rod
% Slider representation
Slider1 = line([Cx(3)+sx, Cx(3)+sx], [Cy(3)+sy, Cy(3)-sy], 'color', 'k', 'linewidth', 1);
Slider2 = line([Cx(3)-sx, Cx(3)-sx], [Cy(3)+sy, Cy(3)-sy], 'color', 'k', 'linewidth', 1);
% Plotting the coupler curve
plot(X(1:i), Y(1:i), 'm', 'Linewidth', 1);
% Animation of Plotting by Deleting the previous plotting
pause(0.05);
if i < numSteps
delete(crank);
delete(coupler);
delete(connecting_rod);
delete(Slider1);
delete(Slider2);
end
end
% Display final position (if needed)
crank = line([Cx(1), Cx(2)], [Cy(1), Cy(2)], 'color', 'r', 'linewidth', 5); % Crank
coupler = line([Cx(2), Cx(4)], [Cy(2), Cy(4)], 'color', 'g', 'linewidth', 5); % Coupler
connecting_rod = line([Cx(2), Cx(3)], [Cy(2), Cy(3)], 'color', 'b', 'linewidth', 5); % Connecting rod
% Display crank radius and slide distance
Crank_Radius = a;
Slide_Distance = max(X) - min(X);
disp(['Crank Radius: ', num2str(Crank_Radius)]);
disp(['Slide Distance: ', num2str(Slide_Distance)]);
In this example missing parameters are assigned with some value for the demonstration.
Best Regards,
Abhishek Chakram
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!