用matlab模拟机械运动

机械原理第八版课后习题8-16
main.m

%% 公共汽车门开闭仿真
clear;clc;
%% 变量定义
x_A = 0; y_A = 0;
L_DE = sqrt(400^2-50^2);
L_AB = 420;
A = [x_A,y_A];
a = 0:0.1:90/57.3;
E_locus = zeros(length(a),2);
D_locus = zeros(length(a),2);
figure(1)
% plot([-800,850],[-110,-110],'r-')
pit_num = 1;
f_n = 'textimage.gif';
%% 更新点坐标'
L_BC = 400;
% syms x y k b x1 y1 x2 y2
z = 1;
for alpha = a
    B(1) = L_AB*cos(alpha); B(2) = -L_AB*sin(alpha);
    syms x y
    [x,y] = solve(y+110,(x-B(1))^2+(y-B(2))^2-L_BC^2);
    answer = vpa([x,y],9);
    answer = double(answer(2,:));
    C(1) = answer(1); C(2) = answer(2);
    syms k b
    [b,k] = solve(abs(B(2)-k*B(1)-b)==50*sqrt(k^2+1),abs(C(2)-k*C(1)-b)==160*sqrt(k^2+1));
    s = double(k);
    b0 = double(b);
    syms x1 y1
    [x1,y1] = solve(y1-s*x1-b0,y1-B(2)+(1/s)*x1-(1/s)*B(1));
    x1 = double(x1);
    y1 = double(y1);
    D(1) = x1;D(2) = y1;
    D_locus(z,1) = x1; D_locus(z,2) = y1;
    syms x2 y2
    [x2,y2] = solve(y2-s*x2-b0,y2-C(2)+(1/s)*x2-(1/s)*C(1));
    x2 = double(x2);
    y2 = double(y2);
    E(1) = x2;E(2) = y2;
    E_locus(z,1) = x2; E_locus(z,2) = y2;
    hold off
    pause(0.01)
    drawlineinthefigure(A,B)
    drawlineinthefigure(B,D)
    drawlineinthefigure(D,E)
    drawlineinthefigure(E,C)
    z = z+1;
    F = getframe(gcf);
    I = frame2im(F);
    [I,map] = rgb2ind(I,256);
    if pit_num == 1
        imwrite(I,map,f_n,'gif','Loopcount',Inf,'Delaytime',0.2);
    else 
        imwrite(I,map,f_n,'gif','Writemode','append','Delaytime',0.2);
    end
    pit_num = pit_num +1;
    
end
% figure(2)
plot(E_locus(:,1),E_locus(:,2),'linewidth',2)
title('E点的运动轨迹')
% figure(3)
hold on
plot(D_locus(:,1),D_locus(:,2),'linewidth',2)
title('D点的运动轨迹')

drawlineinthefigure.m

function [] = drawlineinthefigure(P1,P2)
    x(1) = P1(1);
    x(2) = P2(1);
    y(1) = P1(2);
    y(2) = P2(2);
    plot(x,y,'Linewidth',2)
%     plot([-200,850],[-110,-110],'r--')
    axis([-200 850 -500 200])
    hold on

使用matlab绘制的gif图像
在这里插入图片描述

  • 5
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值