该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
clf;clear
x1=[0.2,4.96,6.55,9.71,13.17,16.23,18.36,20.53,23.15,26.49,28.23,29.1,30.65,30.92,31.67,33.03,34.35,35.01,37.5]
x2=[0.2,1.8,4.90,6.51,9.73,13.18,16.20,18.92,20.50,23.23,25.56,28.31,29.45,30.30,30.92,31.67,33.31,34.23,35.81,37.5]
y1=[6.66,5.28,4.68,5.19,2.34,6.94,5.55,9.86,5.28,3.87,3.04,2.88,3.68,2.38,2.06,2.58,2.16,1.45,6]
y2=[6.66,19.89,24.52,34.82,40.54,37.67,41.38,30.00,19.68,14.56,18.86,18.55,22.66,18.28,15.06,13.42,11.86,7.68,9.45,6]
T=0:0.25:9
v1=4*sqrt((x1(2:19)-x1(1:18)).^2+(y1(2:19)-y1(1:18)).^2)
v2=4*sqrt((x2(20:-1:2)-x2(19:-1:1)).^2+(y2(20:-1:2)-y2(19:-1:1)).^2)
v=[v1,v2]
%画出车道!
subplot(1,2,1)
plot(x1,y1,'r.','markersize',15);
hold on
plot(x2,y2,'k.','markersize',15);
hold on
axis([-5 40 0 45]);
grid;hold on
xlabel('x')
ylabel('y')
title('模拟赛道')
t=-5:0.25:40
u1=spline(x1,y1,t);
plot(t,u1,'b-','linewidth',3)
hold on
u2=spline(x2,y2,t);
plot(t,u2,'b-','linewidth',3)
%画出速度曲线!
subplot(1,2,2)
plot(T,v,'g.','markersize',15);
hold on
axis([0 9 0 55])
grid;hold on
xlabel('时间t/h')
ylabel('速度v/km/h')
title('速度随时间变化曲线')
text(0.1,13,'va=12')
text(0.1,31,'vb=30')
t0=0:0.05:9
w=spline(T,v,t0)
plot(t0,w,'g-','linewidth',3)
hold on
va=12
vb=30
plot(t0,va,'r-','linewidth',3)
hold on
plot(t0,vb,'r-','linewidth',3)
hold on
x=4.5
y=15.3668
plot(x,y,'k.','markersize',15)
%求周长与面积!
s=trapz(t,u2-u1);
p1=sqrt(diff(t).^2+diff(u1).^2);
p2=sqrt(diff(t).^2+diff(u2).^2);
l=sum(p1)+sum(p2);
fprintf('s=%.2f,l=%.2f\n',s,l)
hold on
只能做到这一步了,关于染色,就不会了……