% This program calculates the position the slider in a slider crank mechanism
%in barname jahat moshakhas kardane makane slider dar mechanism slider crank ast
% as a function of the input crank position
%
% VARIABLES
%
% [r(1)..r(4)] - link lengths
% [th(1)..th(4)] - corresponding angles in degrees
% [thr(1) ..thr(4)] - converted angles in radians
% r4 - Array storing all link 4 positions
% th2 - Array storing all link 2 orientations
clear;
clf;
% Enter initial data for link lengths and angles
r=[6,2,0.5]; % r(4) is to be calculated
th(2:4)=[20,90,0]; % note that th1 is to be calculated
thr=th*pi/180; % convert the entire array to radians, entry by entry
%begin position analysis equations
for count=1:360
th(2)=count-1;
thr(2)=th(2)*pi/180;
thr(1)=asin(-(r(2)*sin(thr(2))-r(3))/r(1));
r4(count)=r(2)*cos(thr(2))-r(1)*cos(thr(1)); %CHANGED
th2(count)=th(2);
% BEGIN NEW LINES ADDED FOR PLOTTING
% create an array that has the (x,y) positions of the slider-crank
% joints. The plotting routine will draw a line between them.
x=[0,r(2)*cos(thr(2)),r(2)*cos(thr(2))+r(1)*cos(thr(1))];
y=[0,r(2)*sin(thr(2)),r(2)*sin(thr(2))+r(1)*sin(thr(1))];
% In the plot command, the qualifier ’k-o’ joints all the points
% with a black line and draws a circle at each point
plot(x,y,'k-o')
axis([-3 10 -5 5]) % sets the upper and lower bounds for the axes
axis equal % sets an equal aspect ratio between the x- and y-axes.
grid
% the pause() command pauses your program for the amount of time
% specified within the brackets - 0.001 seconds in this case. In this
% application, we are intentionally slowing the program drown to allow the
% graph to be drawn to the screen before the next plot command is issued.
% If you the ’pause’ command is issued by itself, the program stops until
% the user presses the Enter/Return key.
pause(0.001)
% END NEW LINES FOR PLOTTING
end
% End Program