Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Animation mechanism

Subject: Animation mechanism

From: Ben

Date: 26 Mar, 2009 21:40:19

Message: 1 of 2

Hi guys, I have this code. I plotted these points already. How to i get the lines to move/animate in 360 degree motion, assuming all the variables have known values stored in a master file? This is my code of for a six bar mchanism. Thanks.

pos_r1x = r1*cos(theta_1); %position vector of r1
pos_r1y = r1*sin(theta_1);
pos_r1 = [pos_r1x,pos_r1y];

pos_r2x = r2*cos(theta_2);
pos_r2y = r2*sin(theta_2);
pos_r2 = [pos_r2x,pos_r2y];

pos_r3x = pos_r2x + r3*cos(theta_3);
pos_r3y = pos_r2y + r3*sin(theta_3);
pos_r3 = [pos_r3x,pos_r3y];

pos_r4x = pos_r1x + r4*cos(theta_4);
pos_r4y = pos_r1y + r4*sin(theta_4);
pos_r4 = [pos_r4x,pos_r4y];

pos_r5x = pos_r1x + r5*cos(theta_5);
pos_r5y = pos_r1y + r5*sin(theta_5);
pos_r5 = [pos_r5x,pos_r5y];

pos_r6x = pos_r1x + r6*cos(theta_6);
pos_r6y = pos_r1y + r6*sin(theta_6);
pos_r6 = [pos_r6x,pos_r6y];

pos_r7x = pos_r6x + r7*cos(theta_7);
pos_r7y = pos_r6y + r7*sin(theta_7);
pos_r7 = [pos_r7x,pos_r7y];

pos_r8x = pos_r5x + r8*cos(theta_8);
pos_r8y = pos_r5y + r8*sin(theta_8);
pos_r8 = [pos_r8x,pos_r8y];

pos_rpx = pos_r6x + rp*cos(beta-(theta_7));
pos_rpy = pos_r6y + rp*sin(beta-(theta_7));
pos_rp = [pos_rpx,pos_rpy];


x1 = [0 pos_r2x pos_r3x pos_r1x]; %I just grouped all the points to get the proper
y1 = [0 pos_r2y pos_r3y pos_r1y]; %configiration of my graph

x2 = [pos_r1x pos_r4x pos_r6x pos_r1x];
y2 = [pos_r1y pos_r4y pos_r6y pos_r1y];

x3 = [pos_r1x pos_r6x pos_r7x pos_r5x];
y3 = [pos_r1y pos_r6y pos_r7y pos_r5y];

xp = [pos_r6x pos_rpx pos_r7x];
yp = [pos_r6y pos_rpy pos_r7y];


    plot(x1,y1,'-bo','LineWidth',1.5,...
                'MarkerEdgeColor','r',...
                'MarkerFaceColor','r',...
                'MarkerSize',5);
    hold on;
    plot(x2,y2,'-bo','LineWidth',1.5,...
                'MarkerEdgeColor','r',...
                'MarkerFaceColor','r',...
                'MarkerSize',5);
    hold on;
    plot(x3,y3,'-bo','LineWidth',1.5,...
                'MarkerEdgeColor','r',...
                'MarkerFaceColor','r',...
                'MarkerSize',5);
    hold on;
    plot(xp,yp,'-bo','LineWidth',1.5,...
                'MarkerEdgeColor','r',...
                'MarkerFaceColor','r',...
                'MarkerSize',5);

Subject: Animation mechanism

From: Pieter

Date: 27 Mar, 2009 11:25:25

Message: 2 of 2

Hi Ben,

KUL I suppose?

Write down your bars as vectors; (starting position) + amplitude*exp
(j*omega(t))
(with (starting position) the position from where the vector is
defined)

Put these definitions in a for-loop: eg. for k =3D 1:length(omega), and
also plot the vectors (real, imag) in this for-loop, always is the
same figure. Clear the figure before the first vector in the new loop:
use 'cla'.

hth!

Pieter



On 26 mrt, 22:40, "Ben " <benlawr2...@yahoo.com> wrote:
> Hi guys, I have this code. =A0I plotted these points already. =A0How to i=
 get the lines to move/animate in 360 degree motion, assuming all the varia=
bles have known values stored in a master file? =A0 This is my code of for =
a six bar mchanism. =A0Thanks.
>
> pos_r1x =3D r1*cos(theta_1); %position vector of r1
> pos_r1y =3D r1*sin(theta_1);
> pos_r1 =3D [pos_r1x,pos_r1y];
>
> pos_r2x =3D r2*cos(theta_2);
> pos_r2y =3D r2*sin(theta_2);
> pos_r2 =3D [pos_r2x,pos_r2y];
>
> pos_r3x =3D pos_r2x + r3*cos(theta_3);
> pos_r3y =3D pos_r2y + r3*sin(theta_3);
> pos_r3 =3D [pos_r3x,pos_r3y];
>
> pos_r4x =3D pos_r1x + r4*cos(theta_4);
> pos_r4y =3D pos_r1y + r4*sin(theta_4);
> pos_r4 =3D [pos_r4x,pos_r4y];
>
> pos_r5x =3D pos_r1x + r5*cos(theta_5);
> pos_r5y =3D pos_r1y + r5*sin(theta_5);
> pos_r5 =3D [pos_r5x,pos_r5y];
>
> pos_r6x =3D pos_r1x + r6*cos(theta_6);
> pos_r6y =3D pos_r1y + r6*sin(theta_6);
> pos_r6 =3D [pos_r6x,pos_r6y];
>
> pos_r7x =3D pos_r6x + r7*cos(theta_7);
> pos_r7y =3D pos_r6y + r7*sin(theta_7);
> pos_r7 =3D [pos_r7x,pos_r7y];
>
> pos_r8x =3D pos_r5x + r8*cos(theta_8);
> pos_r8y =3D pos_r5y + r8*sin(theta_8);
> pos_r8 =3D [pos_r8x,pos_r8y];
>
> pos_rpx =3D pos_r6x + rp*cos(beta-(theta_7));
> pos_rpy =3D pos_r6y + rp*sin(beta-(theta_7));
> pos_rp =3D [pos_rpx,pos_rpy];
>
> x1 =3D [0 pos_r2x pos_r3x pos_r1x]; %I just grouped all the points to get=
 the proper
> y1 =3D [0 pos_r2y pos_r3y pos_r1y]; %configiration of my graph
>
> x2 =3D [pos_r1x pos_r4x pos_r6x pos_r1x];
> y2 =3D [pos_r1y pos_r4y pos_r6y pos_r1y];
>
> x3 =3D [pos_r1x pos_r6x pos_r7x pos_r5x];
> y3 =3D [pos_r1y pos_r6y pos_r7y pos_r5y];
>
> xp =3D [pos_r6x pos_rpx pos_r7x];
> yp =3D [pos_r6y pos_rpy pos_r7y];
>
> =A0 =A0 plot(x1,y1,'-bo','LineWidth',1.5,...
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 'MarkerEdgeColor','r',...
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 'MarkerFaceColor','r',...
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 'MarkerSize',5);
> =A0 =A0 hold on;
> =A0 =A0 plot(x2,y2,'-bo','LineWidth',1.5,...
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 'MarkerEdgeColor','r',...
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 'MarkerFaceColor','r',...
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 'MarkerSize',5);
> =A0 =A0 hold on;
> =A0 =A0 plot(x3,y3,'-bo','LineWidth',1.5,...
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 'MarkerEdgeColor','r',...
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 'MarkerFaceColor','r',...
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 'MarkerSize',5);
> =A0 =A0 hold on;
> =A0 =A0 plot(xp,yp,'-bo','LineWidth',1.5,...
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 'MarkerEdgeColor','r',...
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 'MarkerFaceColor','r',...
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 'MarkerSize',5);

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us