您好,欢迎访问三七文档
当前位置:首页 > 机械/制造/汽车 > 汽车理论 > netlogo实现相向行驶的小汽车
在街道上行驶的汽车要求:1.汽车按照上下行车道行驶2.汽车的加速度和减速度,通过滑动空间来调节。行驶过程中不发生碰撞事件。3.能够时时检测汽车在行驶过程中的最大速度和最小速度。4.绘制某一选定汽车在整个运行期间的速度曲线globals[sample-car]turtles-own[speedspeed-limitspeed-min]tosetupclear-allaskpatches[setup-road]setup-carsreset-ticksendtosetup-roadif(pycor20)and(pycor0)[setpcolorwhite]endtosetup-carsset-default-shapeturtlescarcrtnumber-of-cars[setcolorbluesetsize1setshapecarsetxyrandom-xcorrandom-ycorsetheading90;;;setinitialspeedtobeinrange0.1to1.0setspeed0.1+random-float.9setycor2setycorrandom2+6setspeed0.1+random-float.9setspeed-limit1setspeed-min0separate-cars]crtnumber-of-car2s[setcolororangesetsize1setshapecartopsetxyrandom-xcorrandom-ycorsetheading270;;;setinitialspeedtobeinrange0.1to1.0setycorrandom2setycorrandom2+17setspeed0.1+random-float.9setspeed-limit1setspeed-min0separate-cars]setsample-carone-ofturtlesasksample-car[setcolorred]askpatcheswith[pycor=10andpxcor=0andpxcor=50][setpcolor122]endtoseparate-carsifany?otherturtles-here[fd1separate-cars]endtogoaskturtles[letcar-aheadone-ofturtles-onpatch-ahead1ifelsecar-ahead!=nobody[slow-down-carcar-ahead][speed-up-car]ifspeedspeed-min[setspeedspeed-min]ifspeedspeed-limit[setspeedspeed-limit]fdspeed]tickendtoslow-down-car[car-ahead]setspeed[speed]ofcar-ahead-decelerationendtospeed-up-carsetspeedspeed+accelerationend
本文标题:netlogo实现相向行驶的小汽车
链接地址:https://www.777doc.com/doc-7845254 .html