{"id":24063,"date":"2021-02-27T22:46:43","date_gmt":"2021-02-27T14:46:43","guid":{"rendered":"https:\/\/swarma.org\/?p=24063"},"modified":"2021-02-27T22:46:43","modified_gmt":"2021-02-27T14:46:43","slug":"%e4%bb%80%e4%b9%88%e6%98%af%e9%b8%9f%e7%be%a4%e7%ae%97%e6%b3%95-%e9%9b%86%e6%99%ba%e7%99%be%e7%a7%91","status":"publish","type":"post","link":"https:\/\/swarma.org\/?p=24063","title":{"rendered":"\u4ec0\u4e48\u662f\u9e1f\u7fa4\u7b97\u6cd5 | \u96c6\u667a\u767e\u79d1"},"content":{"rendered":"<div class='wxsyncmain'>                                                                                                          <img data-ratio=\"0.4273255813953488\"  data-type=\"jpeg\" data-w=\"344\" style=\"width: 494px;height: 211px;\" src=\"\/wp-content\/uploads\/2021\/03\/wxsync-2021-03-4fc50f8b2c63427b34db32398df103e2.jpeg\"  \/><\/p>\n<p>\u201c\u96c6\u667a\u767e\u79d1\u7cbe\u9009\u201d\u662f\u4e00\u4e2a\u957f\u671f\u4e13\u680f\uff0c\u6301\u7eed\u4e3a\u5927\u5bb6\u63a8\u9001\u590d\u6742\u6027\u79d1\u5b66\u76f8\u5173\u7684\u57fa\u672c\u6982\u5ff5\u548c\u8d44\u6e90\u4fe1\u606f\u3002\u4f5c\u4e3a\u96c6\u667a\u4ff1\u4e50\u90e8\u7684\u5f00\u6e90\u79d1\u5b66\u9879\u76ee\uff0c\u96c6\u667a\u767e\u79d1\u5e0c\u671b\u6253\u9020\u590d\u6742\u6027\u79d1\u5b66\u9886\u57df\u6700\u5168\u9762\u7684\u767e\u79d1\u5168\u4e66\uff0c\u6b22\u8fce\u5bf9\u590d\u6742\u6027\u79d1\u5b66\u611f\u5174\u8da3\u3001\u70ed\u7231\u77e5\u8bc6\u6574\u7406\u548c\u5206\u4eab\u7684\u670b\u53cb\u52a0\u5165\uff01<\/p>\n<p>\u672c\u6587\u662f\u5bf9\u96c6\u667a\u767e\u79d1\u4e2d\u201c\u9e1f\u7fa4\u7b97\u6cd5\u201d\u8bcd\u6761\u7684\u6458\u5f55\uff0c\u53c2\u8003\u8d44\u6599\u53ca\u76f8\u5173\u8bcd\u6761\u8bf7\u53c2\u9605\u767e\u79d1\u8bcd\u6761\u539f\u6587\u3002<br  \/>\u672c\u8bcd\u6761\u7531\u96c6\u667a\u4ff1\u4e50\u90e8\u4f17\u5305\u751f\u4ea7\uff0c\u96be\u514d\u5b58\u5728\u7eb0\u6f0f\u548c\u95ee\u9898\uff0c\u6b22\u8fce\u5927\u5bb6\u7559\u8a00\u53cd\u9988\u6216\u8005\u524d\u5f80\u5bf9\u5e94\u7684\u767e\u79d1\u8bcd\u6761\u9875\u9762\u8fdb\u884c\u4fee\u6539\uff0c\u4e00\u7ecf\u4fee\u6539\uff0c\u53ef\u4ee5\u83b7\u5f97\u5bf9\u5e94\u7684\u79ef\u5206\u5956\u52b1\u5662\uff01<br  \/>\u672c\u8bcd\u6761\u7531\u96c6\u667a\u4ff1\u4e50\u90e8\u4f17\u5305\u751f\u4ea7\uff0c\u96be\u514d\u5b58\u5728\u7eb0\u6f0f\u548c\u95ee\u9898\uff0c\u6b22\u8fce\u5927\u5bb6\u7559\u8a00\u53cd\u9988\u6216\u8005\u524d\u5f80\u5bf9\u5e94\u7684\u767e\u79d1\u8bcd\u6761\u9875\u9762\u8fdb\u884c\u4fee\u6539\uff0c\u4e00\u7ecf\u4fee\u6539\uff0c\u53ef\u4ee5\u83b7\u5f97\u5bf9\u5e94\u7684\u79ef\u5206\u5956\u52b1\u5662\uff01<\/p>\n<p>\u76ee\u5f55<\/p>\n<p>\u4e00\u3001\u7b97\u6cd5\u4ecb\u7ecd\u4e8c\u3001\u4ee3\u7801\u5b9e\u73b0\u4e09\u3001\u7f16\u8005\u63a8\u8350\u56db\u3001\u96c6\u667a\u767e\u79d1\u8bcd\u6761\u5fd7\u613f\u8005\u62db\u52df<\/p>\n<div class=\"post-image\"><img class=\"rich_pages\" data-ratio=\"0.5605680868838764\" data-s=\"300,640\"  data-type=\"png\" data-w=\"1197\" style=\"\" src=\"\/wp-content\/uploads\/2021\/03\/wxsync-2021-03-ccd72ba9dbdea2cef18ed27be1a5b4c3.png\"  \/><br \/>\u9e1f\u7fa4\u7b97\u6cd5 Boids\u662f\u6a21\u62df\u9e1f\u7c7b\u7fa4\u96c6\u884c\u4e3a\u7684\u4eba\u5de5\u751f\u547d\u9879\u76ee\uff0c\u7531\u514b\u96f7\u683c\u00b7\u96f7\u8bfa\u5179 Craig Reynolds\u4e8e1986\u5e74\u5f00\u53d1\u3002\u8be5\u6a21\u578b\u5e38\u7528\u4e8e\u8ba1\u7b97\u673a\u52a8\u753b\u6216\u8ba1\u7b97\u673a\u8f85\u52a9\u8bbe\u8ba1\u7684\u8ba1\u7b97\u673a\u4e09\u7ef4\u51e0\u4f55\u3002\u4ed6\u5173\u4e8e\u8fd9\u4e2a\u4e3b\u9898\u7684\u8bba\u6587\u53d1\u8868\u57281987\u5e74\u7684 ACM SIGGRAPH\uff08\u7f8e\u56fd\u8ba1\u7b97\u673a\u534f\u4f1a\u8ba1\u7b97\u673a\u56fe\u5f62\u4e13\u4e1a\u7ec4\u7ec4\u7ec7\u7684\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\u9876\u7ea7\u5e74\u5ea6\u4f1a\u8bae\uff09\u4f1a\u8bae\u8bb0\u5f55\u4e0a\u3002\u201c boid\u201d\u662f\u201c bird-oid object\u201d\u7684\u7f29\u5199\uff0c\u6307\u4e00\u4e2a\u7c7b\u9e1f\u5bf9\u8c61\u3002\u6070\u5de7\uff0c\u201cboid\u201d\u4e5f\u662f\u7ebd\u7ea6\u90fd\u5e02\u65b9\u8a00\u4e2d\u201cbird\u201d\u7684\u53d1\u97f3\u3002<br \/><br mpa-from-tpl=\"t\"  \/><\/div>\n<p><br style=\"max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;\" mpa-from-tpl=\"t\"  \/><br style=\"max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;\" mpa-from-tpl=\"t\"  \/>\u7b97\u6cd5\u4ecb\u7ecd<br \/><br style=\"max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;\" mpa-from-tpl=\"t\"  \/><br mpa-from-tpl=\"t\"  \/><\/p>\n<p>\u4e0e\u5927\u591a\u6570\u4eba\u5de5\u751f\u547d\u6a21\u62df\u4e00\u6837\uff0cBoids \u662f\u6d8c\u73b0\u884c\u4e3a\u7684\u4e00\u4e2a\u4f8b\u5b50; \u4e5f\u5c31\u662f\u8bf4\uff0cBoids \u7684\u590d\u6742\u6027\u6765\u81ea\u4e8e\u9075\u5faa\u4e00\u7cfb\u5217\u7b80\u5355\u89c4\u5219\u4e2a\u4f53 agents\uff08\u8fd9\u91cc\u662f Boids\uff09\u7684\u76f8\u4e92\u4f5c\u7528\u3002\u5728\u6700\u7b80\u5355\u7684Boids\u4e16\u754c\u4e2d\u9002\u7528\u7684\u89c4\u5219\u5982\u4e0b\uff0c\u5176\u63cf\u8ff0\u4e86\u9e1f\u7fa4\u4e2d\u7684\u4e2a\u4f53\u5982\u4f55\u6839\u636e\u5468\u8fb9\u540c\u4f34\u7684\u4f4d\u7f6e\u548c\u901f\u5ea6\u79fb\u52a8:<br \/>\u5206\u79bb Separation: \u79fb\u52a8\u4ee5\u907f\u5f00\u7fa4\u4f53\u62e5\u6324\u5904\u5bf9\u9f50 Alignment: \u671d\u7740\u5468\u56f4\u540c\u4f34\u7684\u5e73\u5747\u65b9\u5411\u524d\u8fdb\u9760\u8fd1 Cohesion: \u671d\u7740\u5468\u56f4\u540c\u4f34\u7684\u5e73\u5747\u4f4d\u7f6e\uff08\u8d28\u5fc3\uff09\u79fb\u52a8<img data-ratio=\"0.67\"  data-type=\"jpeg\" data-w=\"200\" src=\"\/wp-content\/uploads\/2021\/03\/wxsync-2021-03-6c5c1e47e3100e9f752c7d6b0fecc6d0.jpeg\"  \/>\u5206\u79bb<img data-ratio=\"0.67\"  data-type=\"jpeg\" data-w=\"200\" src=\"\/wp-content\/uploads\/2021\/03\/wxsync-2021-03-dba8749e3888d704a9cc09c56b3fffd2.jpeg\"  \/>\u5bf9\u9f50<img data-ratio=\"0.67\"  data-type=\"jpeg\" data-w=\"200\" src=\"\/wp-content\/uploads\/2021\/03\/wxsync-2021-03-783f0001307af42445c55fe0b1a6ce90.jpeg\"  \/>\u9760\u8fd1\u6bcf\u4e2a boid \u4e2a\u4f53\u90fd\u53ef\u4ee5\u5f97\u77e5\u6574\u4f53\u7684\u51e0\u4f55\u53c2\u6570\uff0c\u4f46\u7fa4\u4f53\u8981\u6c42\u5176\u53ea\u5bf9\u5176\u5468\u56f4\u67d0\u4e2a\u5c0f\u90bb\u8fd1\u8303\u56f4\u4f5c\u51fa\u53cd\u5e94\u3002\u8be5\u90bb\u8fd1\u8303\u56f4\u7531\u4e00\u4e2a\u8ddd\u79bb\uff08\u4ece\u8be5\u4e2a\u4f53\u7684\u4e2d\u5fc3\u7b97\u8d77\uff09\u548c\u4e00\u4e2a\u89d2\u5ea6\uff08\u4ece\u5176\u98de\u884c\u65b9\u5411\u7b97\u8d77\uff09\u51b3\u5b9a\u3002\u6b64\u8303\u56f4\u5916\u7684\u540c\u4f34\u4e0d\u4e88\u8003\u8651\u3002\u8be5\u4e34\u8fd1\u8303\u56f4\u53ef\u4ee5\u8ba4\u4e3a\u662f\u4e00\u4e2a\u6709\u9650\u77e5\u89c9\u7684\u6a21\u578b\uff08\u5c31\u50cf\u6d51\u6c34\u4e2d\u7684\u9c7c\u4e00\u6837\uff09\uff1b\u4f46\u66f4\u6070\u5f53\u7684\u60f3\u6cd5\u53ef\u80fd\u662f\uff0c\u5176\u5b9a\u4e49\u4e86\u9e1f\u7fa4\u5f71\u54cd\u4e86\u4e2a\u4f53\u8f6c\u5411\u7684\u533a\u57df\u8303\u56f4\u3002<br  \/>\u5f53\u7136\u4e5f\u53ef\u4ee5\u6dfb\u52a0\u66f4\u590d\u6742\u7684\u89c4\u5219\uff0c\u5982\u907f\u969c\u548c\u5bfb\u627e\u76ee\u6807\u3002<br  \/>\u8be5\u57fa\u672c\u6a21\u578b\u81eaReynolds\u63d0\u51fa\u4ee5\u6765\uff0c\u5df2\u7528\u591a\u79cd\u65b9\u6cd5\u6269\u5c55\u3002\u4f8b\u5982\uff0cDelgado-Mata \u7b49\u4eba\u6269\u5c55\u57fa\u672c\u6a21\u578b\u4ee5\u52a0\u5165\u6050\u60e7\u7684\u5f71\u54cd\u3002\u56e0\u4e3a\u52a8\u7269\u4e4b\u95f4\u9760\u55c5\u89c9\u6765\u4f20\u9012\u60c5\u611f\uff0c\u6240\u4ee5\u4ed6\u5229\u7528\u4e00\u79cd\u53ef\u81ea\u7531\u81a8\u80c0\u6c14\u4f53\u4e2d\u7684\u7c92\u5b50\u6765\u6a21\u62df\u4fe1\u606f\u7d20\u3002\u54c8\u7279\u66fc Hartman\u548c\u8d1d\u5185\u65af Benes\u6211\u4eec\u4e3a\u8fd9\u79cd\u7ed3\u76df\u5f15\u5165\u4e86\u4e92\u8865\u7684\u529b\u91cf\uff0c\u79f0\u4e4b\u4e3a\u9886\u5bfc\u529b\u66f4\u66ff\u3002\u8fd9\u4e2a\u529b\u51b3\u5b9a\u4e86\u8fd9\u4e2a\u9e1f\u6210\u4e3a\u9886\u5bfc\u8005\u6216\u8005\u8bd5\u56fe\u9003\u8131\u7fa4\u4f53\u7684\u6982\u7387\u3002<br  \/>Boids \u7684\u8fd0\u52a8\u53ef\u4ee5\u8868\u73b0\u4e3a\u6df7\u4e71\uff08\u5206\u88c2\u7684\u7fa4\u4f53\u548c\u72c2\u91ce\u7684\u884c\u4e3a\uff09\u6216\u6709\u5e8f\u3002\u610f\u60f3\u4e0d\u5230\u7684\u884c\u4e3a\u6bd4\u5982\u7fa4\u4f53\u5206\u6563\u548c\u907f\u5f00\u969c\u788d\u540e\u7684\u96c6\u805a\uff0c\u53ef\u4ee5\u88ab\u8ba4\u4e3a\u662f\u6d8c\u73b0\u7684\u3002<br  \/>Boids \u6846\u67b6\u901a\u5e38\u7528\u4e8e\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\uff0c\u63d0\u4f9b\u9e1f\u7fa4\u548c\u5176\u4ed6\u751f\u7269\uff08\u5982\u9c7c\u7fa4\uff09\u7684\u903c\u771f\u8868\u73b0\u3002\u4f8b\u5982\uff0c\u57281998\u5e74\u7684\u7535\u5b50\u6e38\u620f\u300a\u534a\u6761\u547d Half-Life\u300b\u4e2d\uff0c\u6e38\u620f\u7ed3\u675f\u65f6Xen\u4e2d\u51fa\u73b0\u7684\u7c7b\u4f3c\u9e1f\u7c7b\u7684\u98de\u884c\u751f\u7269\u5c31\u4f7f\u7528\u4e86\u8be5\u6846\u67b6\uff08\u6e38\u620f\u6587\u4ef6\u4e2d\u547d\u540d\u4e3a\u201c boid\u201d\uff09\u3002<br  \/>Boids \u6a21\u578b\u53ef\u7528\u4e8e\u96c6\u7fa4\u673a\u5668\u4eba&nbsp;Swarm Robotics\u4e2d\u7b80\u5355\u7684\u65e0\u4eba\u5730\u9762\u8f66\u8f86\uff08UGV\uff09\u6216\u5fae\u578b\u98de\u884c\u5668 Micro Aerial Vehicles\uff08MAV\uff09\u7fa4\u4f53\u7684\u76f4\u63a5\u63a7\u5236\u548c\u7a33\u5b9a\u3002\u4e3a\u4e86\u5f02\u8d28 UAV-UGV \u7fa4\u4f53\u7684\u7a33\u5b9a\u6027\uff0cSaska \u7b49\u4eba\u5c06\u8be5\u6a21\u578b\u7528\u4e8e\u677f\u8f7d\u76f8\u5bf9\u5b9a\u4f4d\u3002<br  \/>\u5728\u5f53\u65f6\u63d0\u51fa\u65f6\uff0cReynolds\u7684\u65b9\u6cd5\u76f8\u6bd4\u4e8e\u4f20\u7edf\u7684\u8ba1\u7b97\u673a\u52a8\u753b\u7535\u5f71\u6280\u672f\u662f\u4e00\u4e2a\u5de8\u5927\u7684\u8fdb\u6b65\u3002\u7b2c\u4e00\u90e8\u5229\u7528\u4e86\u6b64\u6a21\u578b\u7684\u52a8\u753b\u7247\u662f\u300a\u53f2\u4e39\u5229\u548c\u53f2\u9edb\u62c9: \u7834\u51b0 Stanley and Stella in: Breaking The Ice\u300b\uff081987\uff09\uff0c\u4e4b\u540e\u662f\u8482\u59c6\u00b7\u4f2f\u987f Tim Burton\u7684\u6545\u4e8b\u7247\u300a\u8759\u8760\u4fa0\u5f52\u6765 Batman Returns\u300b\uff081992\uff09\uff0c\u7535\u8111\u5408\u6210\u7684\u8759\u8760\u7fa4\u548c\u6210\u7fa4\u7684\u4f01\u9e45\u884c\u8fdb\u7a7f\u8fc7\u54e5\u8c2d\u5e02 Gotham City\u7684\u8857\u9053\u3002<br  \/>Boids \u6a21\u578b\u5df2\u7ecf\u88ab\u7528\u4e8e\u5176\u4ed6\u6709\u8da3\u5e94\u7528\u3002\u8be5\u7cfb\u7edf\u5df2\u5e94\u7528\u4e8e\u4e92\u8054\u7f51\u591a\u9891\u9053\u5e7f\u64ad\u7535\u53f0\u7684\u81ea\u52a8\u8282\u76ee\u7f16\u6392\uff0c\u5b83\u4e5f\u88ab\u7528\u4e8e\u53ef\u89c6\u5316\u4fe1\u606f\u548c\u4f18\u5316\u4efb\u52a1\u3002\u4ee5\u53ca\u53ef\u89c6\u5316\u4fe1\u606f\u548c\u4f18\u5316\u4efb\u52a1\u3002<br style=\"max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;\" mpa-from-tpl=\"t\"  \/><br \/><br style=\"max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;\" mpa-from-tpl=\"t\"  \/><br \/><br style=\"max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;\" mpa-from-tpl=\"t\"  \/><br style=\"max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;\" mpa-from-tpl=\"t\"  \/>\u4ee3\u7801\u5b9e\u73b0<br \/><br style=\"max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;\" mpa-from-tpl=\"t\"  \/><br mpa-from-tpl=\"t\"  \/><br  \/>\u4ee5\u4e0b\u5185\u5bb9\u662f\u4f7f\u7528BOIDS\u4e09\u5c42\u6a21\u578b\u5bf9\u9e1f\u7fa4\u8fd0\u52a8\u8fdb\u884c\u4e86\u6a21\u62df\uff0c\u53ef\u4ee5\u901a\u8fc7\u8c03\u8282\u4e0d\u540c\u7684\u53c2\u6570\u83b7\u53d6\u5230\u4e0d\u540c\u7684\u5b9e\u9a8c\u73b0\u8c61\uff0c\u53ef\u4ee5\u5728\u8fd9\u4e2a\u57fa\u7840\u4e0a\u4fee\u6539\u6a21\u578b\u89c4\u5219\uff0c\u4ee5\u66f4\u597d\u7684\u6a21\u62df\u96c6\u7fa4\u8fd0\u52a8\uff0c\u672c\u6587\u63d0\u4f9b\u4e00\u4e2a\u6a21\u677f\u3002\u4ee3\u7801\u6765\u6e90\u662f\u6c90\u96e8\u6a59\u98cefire\u6240\u5199\u7684\u535a\u5ba2\u3002# -*- coding:utf-8 -*-<br  \/>import argparse<br  \/>import math<br  \/>import numpy as np<br  \/>import matplotlib.pyplot as plt<br  \/>import matplotlib.animation as animation<br  \/>from scipy.spatial.distance import squareform, pdist<br  \/>from numpy.linalg import norm<\/p>\n<p>width, height = 1920, 1080<\/p>\n<p>N = 100             # number of birds<br  \/>minDist = 100.0      # min dist of approach<br  \/>maxRuleVel = 0.3    # max magnitude of velocities calculated by &#8220;rules&#8221;<br  \/>maxVel = 3.0        # max magnitude of final velocity<\/p>\n<p> <br  \/>class Birds:<br  \/>    &#8220;&#8221;&#8221;<br  \/>    Simulates flock behaviour of birds, using the realistic-looking Boids model (1986)<br  \/>    &#8220;&#8221;&#8221;<br  \/>    def __init__(self):<br  \/>        self.N = N<br  \/>        self.minDist = minDist<br  \/>        self.maxRuleVel = maxRuleVel<br  \/>        self.maxVel = maxVel<\/p>\n<p>        # Computing initial position and velocity<br  \/>        self.pos = [width \/ 2.0, height \/ 2.0] + 10 * np.random.rand(2 * N).reshape(N, 2)<br  \/>        # Create an array of N random variable angles in the range [0. 2pi]<br  \/>        angles = 2 * math.pi * np.random.rand(N)<br  \/>        # Random velocity vector [x,y] coordinates zip grouped<br  \/>        self.vel = np.array(list(zip(np.sin(angles), np.cos(angles))))<br  \/>    def savef(self):<br  \/>        with open(&#8220;douban.txt&#8221;, &#8220;a&#8221;) as f:<br  \/>            f.write(str(self.pos.reshape(1, N*2)))<br  \/>            print str(self.pos.reshape(1, N*2))<br  \/>            f.close()<br  \/>    def tick(self, frameNum, pts, beak):<br  \/>        &#8220;&#8221;&#8221;<br  \/>        Update the simulation by one time step<br  \/>        &#8220;&#8221;&#8221;<br  \/>        # get pairwise distances<br  \/>        self.distMatrix = squareform(pdist(self.pos))<br  \/>        # apply rules:<br  \/>        self.vel += self.apply_rules()<br  \/>        self.limit(self.vel, self.maxVel)<br  \/>        self.pos += self.vel<br  \/>        self.apply_bc()<br  \/>        # update data<br  \/>        pts.set_data(self.pos.reshape(2 * self.N)[::2],<br  \/>                     self.pos.reshape(2 * self.N)[1::2])<br  \/>        vec = self.pos + 10 * self.vel \/ self.maxVel<br  \/>        beak.set_data(vec.reshape(2 * self.N)[::2],<br  \/>                      vec.reshape(2 * self.N)[1::2])<br  \/>        self.savef()<br  \/>        #print self.pos.reshape(2 * self.N)<br  \/>        #np.savetxt(&#8220;x.txt&#8221;, self.pos.reshape(1, 2*N))<br  \/>    def limit_vec(self, vec, max_val):<br  \/>        &#8220;&#8221;&#8221; Limit magnitude of 2D vector &#8220;&#8221;&#8221;<br  \/>        mag = norm(vec)<br  \/>        if mag &gt; max_val:<br  \/>            vec[0], vec[1] = vec[0] * max_val \/ mag, vec[1] * max_val \/ mag<\/p>\n<p>    def limit(self, x, max_val):<br  \/>        &#8220;&#8221;&#8221; Limit magnitide of 2D vectors in array X to maxValue &#8220;&#8221;&#8221;<br  \/>        for vec in x:<br  \/>            self.limit_vec(vec, max_val)<\/p>\n<p>    def apply_bc(self):<br  \/>        &#8220;&#8221;&#8221; Apply boundary conditions &#8220;&#8221;&#8221;<br  \/>        deltaR = 2.0<br  \/>        for coord in self.pos:<br  \/>            if coord[0] &gt; width + deltaR:<br  \/>                coord[0] = &#8211; deltaR<br  \/>            if coord[0] &lt; &#8211; deltaR:<br  \/>                coord[0] = width + deltaR<br  \/>            if coord[1] &gt; height + deltaR:<br  \/>                coord[1] = &#8211; deltaR<br  \/>            if coord[1] &lt; &#8211; deltaR:<br  \/>                coord[1] = height + deltaR<\/p>\n<p>    def apply_rules(self):<br  \/>        # apply rule #1 &#8211; Separation<br  \/>        D = self.distMatrix &lt; 20.0<br  \/>        vel = self.pos * D.sum(axis=1).reshape(self.N, 1) &#8211; D.dot(self.pos)<br  \/>        self.limit(vel, self.maxRuleVel)<\/p>\n<p>        # different distance threshold<br  \/>        D = self.distMatrix &lt; 50.0<\/p>\n<p>        # apply rule #2 &#8211; Alignment<br  \/>        vel2 = D.dot(self.vel)<br  \/>        self.limit(vel2, self.maxRuleVel)<br  \/>        vel += vel2<\/p>\n<p>        # apply rule #1 &#8211; Cohesion<br  \/>        vel3 = D.dot(self.pos) &#8211; self.pos<br  \/>        self.limit(vel3, self.maxRuleVel)<br  \/>        vel += vel3<\/p>\n<p>        return vel<\/p>\n<p> <br  \/>def tick(frameNum, pts, beak, birds):<br  \/>    &#8220;&#8221;&#8221; Update function for animation &#8220;&#8221;&#8221;<br  \/>    birds.tick(frameNum, pts, beak)<br  \/>    return pts, beak<\/p>\n<p> <br  \/>def main():<br  \/>    print(&#8216;Starting flock simulation&#8230;&#8217;)<\/p>\n<p>    # Create birds<br  \/>    birds = Birds()<\/p>\n<p>    # Setup plot<br  \/>    fig = plt.figure()<br  \/>    ax = plt.axes(xlim=(0, width), ylim=(0, height))<br  \/>    pts, = ax.plot([], [], markersize=10, c=&#8217;k&#8217;, marker=&#8217;o&#8217;, ls=&#8217;None&#8217;)<br  \/>    beak, = ax.plot([], [], markersize=4, c=&#8217;r&#8217;, marker=&#8217;o&#8217;, ls=&#8217;None&#8217;)<br  \/>    anim = animation.FuncAnimation(fig, tick, fargs=(pts, beak, birds), interval=20)<\/p>\n<p>    # TODO: add a &#8220;button press&#8221; event handler to scatter birds<br  \/>    #anim.save(&#8216;basic_animation.mp4&#8217;, fps=30, extra_args=[&#8216;-vcodec&#8217;, &#8216;libx264&#8217;])<br  \/>    plt.show(anim)<br  \/>if __name__ == &#8216;__main__&#8217;:<br  \/>    main()<\/p>\n<p><br style=\"max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;\" mpa-from-tpl=\"t\"  \/><br style=\"max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;\" mpa-from-tpl=\"t\"  \/>\u7f16\u8005\u63a8\u8350<br \/><br style=\"max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;\" mpa-from-tpl=\"t\"  \/><\/p>\n<p>\u900f\u8fc7\u4eba\u5de5\u9e1f\u7fa4Boid\u6a21\u578b\u5b66\u4e60List\u7684\u4f7f\u7528\u8bb2\u5e08\uff1a\u5f20\u6c5f(\u5317\u5e08\u5927\u7cfb\u7edf\u79d1\u5b66\u5b66\u9662\u6559\u6388\u3001\u535a\u58eb\u751f\u5bfc\u5e08\uff0c\u96c6\u667a\u4ff1\u4e50\u90e8\u3001\u96c6\u667a\u5b66\u56ed\u521b\u59cb\u4eba\u3002)\u672c\u8bfe\u7a0b\u901a\u8fc7\u6570\u4e2a\u6848\u4f8b\u6559\u4f1a\u5927\u5bb6\u5982\u4f55\u53bb\u52a8\u624b\u642d\u5efa\u4e00\u4e2a\u591a\u4e3b\u4f53\u4eff\u771f\u6a21\u578b\uff0c\u4ee5\u53ca\u5982\u4f55\u5229\u7528NetLogo\u53bb\u5b9e\u73b0\u3002\u4ece\u751f\u547d\u6e38\u620f\u5230\u4eba\u5de5\u9e1f\u7fa4\uff0c\u4ece\u6a21\u62df\u7ecf\u6d4e\u7cfb\u7edf\u5230\u75c5\u6bd2\u6cbf\u7f51\u7edc\u7684\u4f20\u64ad\uff0c\u901a\u8fc7\u5faa\u5e8f\u6e10\u8fdb\u7684\u6848\u4f8b\uff0c\u8be5\u8bfe\u7a0b\u5e26\u4f60\u9010\u6b65\u8d70\u5165NetLogo\u591a\u4e3b\u4f53\u5efa\u6a21\u7684\u795e\u5947\u4e16\u754c\u3002<br  \/><img class=\"rich_pages\" data-ratio=\"0.3856317093311313\" data-s=\"300,640\"  data-type=\"png\" data-w=\"1211\" style=\"\" src=\"\/wp-content\/uploads\/2021\/03\/wxsync-2021-03-b13329e1d7e42a859f83d2fb3875c9bb.png\"  \/><\/p>\n<p>\u8bfe\u7a0b\u63a8\u8350\uff1a\u900f\u8fc7\u4eba\u5de5\u9e1f\u7fa4Boid\u6a21\u578b\u5b66\u4e60List\u7684\u4f7f\u7528<br \/>https:\/\/campus.swarma.org\/course\/1104<\/p>\n<p>\u96c6\u667a\u76f8\u5173\u6587\u7ae0<a target=\"_blank\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzIzMjQyNzQ5MA==&amp;mid=2247498649&amp;idx=1&amp;sn=99d51d6668aafda22b8fa016aa393b04&amp;chksm=e897a114dfe028020904c082d6b4dec09164e59df05f065e3c8a59a55dac0cffac353197e2ea&amp;scene=21#wechat_redirect\" data-itemshowtype=\"11\" tab=\"innerlink\" data-linktype=\"2\" rel=\"noopener noreferrer\">\u5f20\u6c5f\uff1a\u4e4c\u5408\u4e4b\u4f17\u8fd8\u662f\u7fa4\u667a\u6d8c\u73b0\uff1f\u9e1f\u7fa4\u77e5\u9053\u7b54\u6848<\/a><br  \/>\u751f\u547d\u5982\u4f55\u8d77\u6e90\uff0c\u667a\u80fd\u5982\u4f55\u6d8c\u73b0\uff0c\u56e0\u679c\u5982\u4f55\u53cd\u8f6c\uff0c\u590d\u6742\u8c1c\u9898\uff0c\u5f15\u4eba\u6df1\u601d\u30022019\u5e747\u670813\u65e5\uff0c\u96c6\u667a\u4ff1\u4e50\u90e8\u521b\u59cb\u4eba\u5f20\u6c5f\u6559\u6388\u5728\u6df7\u6c8c\u5927\u5b66\u6388\u8bfe\uff0c\u8be6\u7ec6\u89e3\u8bfb\u4e86\u590d\u6742\u7cfb\u7edf\u4e2d\u7684\u6df7\u6c8c\u3001\u6d8c\u73b0\u4e0e\u8fdb\u5316\uff0c\u6b64\u6587\u6574\u7406\u81ea\u8bfe\u5802\u5185\u5bb9\u3002<br  \/>\u5176\u4ed6\u52a8\u753b\u7247\u300aStanley and Stella in: Breaking the Ice (1987)\u300bhttps:\/\/v.qq.com\/x\/page\/z13491sn7fy.html<br \/>Craig Reynolds \u4e0e Symbolics Graphics \u548c Whitney \/ Demos Production \u7684\u540c\u4e8b\u5408\u4f5c\u5236\u4f5c\u7684\u5229\u7528 boids \u6a21\u578b\u7684\u5c0f\u77ed\u7247\uff0c\u8bb2\u8ff0\u4e86\u98de\u9e1f\u4e0e\u9c7c\u76f8\u7231\uff0c\u9e1f\u513f\u51b2\u7834\u51b0\u9762\u4e0e\u9c7c\u76f8\u89c1\u7684\u6545\u4e8b\u3002\u5f71\u7247\u6700\u65e9\u4e8e87\u5e74\u5728 SIGGRAPH \u7535\u5b50\u5267\u9662\u5c55\u51fa\u3002<br style=\"max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;\" mpa-from-tpl=\"t\"  \/><br \/><br style=\"max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;\" mpa-from-tpl=\"t\"  \/><br \/><br style=\"max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;\" mpa-from-tpl=\"t\"  \/><br style=\"max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;\" mpa-from-tpl=\"t\"  \/>\u767e\u79d1\u9879\u76ee\u5fd7\u613f\u8005\u62db\u52df<br \/><br style=\"max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;\" mpa-from-tpl=\"t\"  \/><br mpa-from-tpl=\"t\"  \/><br mpa-from-tpl=\"t\"  \/><br \/>\u4f5c\u4e3a\u96c6\u667a\u767e\u79d1\u9879\u76ee\u56e2\u961f\u7684\u6210\u5458\uff0c\u672c\u6587\u5185\u5bb9\u7531Dorr\uff0c\u6728\u5b50\u4e8c\u6708\u9e1f\uff0c\u8584\u8377\u53c2\u4e0e\u8d21\u732e\u3002\u6211\u4eec\u4e5f\u4e3a\u6bcf\u4f4d\u4f5c\u8005\u548c\u5fd7\u613f\u8005\u51c6\u5907\u4e86\u4e13\u5c5e\u7b80\u4ecb\u548c\u4e2a\u4eba\u96c6\u667a\u767e\u79d1\u4e3b\u9875\uff0c\u66f4\u591a\u4fe1\u606f\u53ef\u4ee5\u8bbf\u95ee\u5176\u96c6\u667a\u767e\u79d1\u4e2a\u4eba\u4e3b\u9875\u3002<\/p>\n<p>\u4ee5\u4e0a\u5185\u5bb9\u90fd\u662f\u6211\u4eec\u505a\u8fd9\u9879\u76ee\u7684\u8d77\u70b9\uff0c\u4f5c\u4e3a\u6765\u81ea\u4e0d\u540c\u5b66\u79d1\u548c\u9886\u57df\u7684\u5fd7\u613f\u8005\uff0c\u6211\u4eec\u5efa\u7acb\u8d77\u4e00\u4e2a\u6709\u6548\u7684\u767e\u79d1\u56e2\u961f\uff0c\u5206\u914d\u6709\u5ba1\u6821\u3001\u7ffb\u8bd1\u3001\u7f16\u8f91\u3001\u5ba3\u4f20\u7b49\u5de5\u4f5c\u3002\u6211\u4eec\u79c9\u6301\uff1a\u77e5\u8bc6\u4ece\u6211\u800c\u6765\uff0c\u95ee\u9898\u5230\u6211\u4e3a\u6b62\u7684\u4fe1\u5ff5\uff0c\u8ba4\u771f\u8d1f\u8d23\u7f16\u64b0\u6bcf\u4e00\u4e2a\u8bcd\u6761\u3002<\/p>\n<div class=\"post-image\"><img class=\"rich_pages\" data-ratio=\"0.5555555555555556\" data-s=\"300,640\" data-type=\"png\" data-w=\"900\"  style=\"box-sizing: border-box !important;visibility: visible !important;width: 677px !important;\" src=\"\/wp-content\/uploads\/2021\/03\/wxsync-2021-03-96a62292ad1641ec07d2bdfec113a955.png\"  \/><\/div>\n<p>\u5728\u8fd9\u91cc\u4ece\u590d\u6742\u6027\u77e5\u8bc6\u51fa\u53d1\u4e0e\u4f19\u4f34\u540c\u884c\uff0c\u540c\u65f6\u6211\u4eec\u5e0c\u671b\u6709\u66f4\u591a\u5fd7\u613f\u8005\u52a0\u5165\u8fd9\u4e2a\u56e2\u961f\uff0c\u4f7f\u767e\u79d1\u8bcd\u6761\u5185\u5bb9\u5f97\u5230\u6269\u5145\uff0c\u5e76\u4e3a\u6bcf\u4f4d\u5fd7\u613f\u8005\u63d0\u4f9b\u76f8\u5e94\u5956\u52b1\u4e0e\u8d44\u6e90\uff0c\u5efa\u7acb\u4e2a\u4eba\u4e3b\u9875\u4e0e\u8d21\u732e\u8bb0\u5f55\uff0c\u4f7f\u5176\u80fd\u591f\u7ee7\u7eed\u63a2\u7d22\u590d\u6742\u4e16\u754c\u3002<\/p>\n<p>\u5982\u679c\u4f60\u6709\u610f\u53c2\u4e0e\u66f4\u52a0\u7cfb\u7edf\u7cbe\u7ec6\u7684\u5206\u5de5\uff0c\u626b\u63cf\u4e8c\u7ef4\u7801\u586b\u5199\u62a5\u540d\u8868\uff0c\u6211\u4eec\u671f\u5f85\u4f60\u7684\u52a0\u5165\uff01<\/p>\n<p><img class=\"rich_pages\" data-cropselx1=\"0\" data-cropselx2=\"562\" data-cropsely1=\"0\" data-cropsely2=\"312\" data-ratio=\"1\" data-s=\"300,640\" data-type=\"png\" data-w=\"500\"  style=\"box-sizing: border-box !important;visibility: visible !important;width: 188px !important;\" src=\"\/wp-content\/uploads\/2021\/03\/wxsync-2021-03-2362e8c744727da7bd820ef764b6029b.png\"  \/>\u96c6\u667a\u767e\u79d1\u62a5\u540d\u8868<\/p>\n<p>\u6765\u6e90\uff1a\u96c6\u667a\u767e\u79d1<br \/>\u7f16\u8f91\uff1a\u738b\u5efa\u840d<\/p>\n<p>\u63a8\u8350\u9605\u8bfb<br  \/><a target=\"_blank\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzIzMjQyNzQ5MA==&amp;mid=2247522522&amp;idx=1&amp;sn=0eba796b1d231f3c9218a8a32683922b&amp;chksm=e897c257dfe04b41bfe572ef4d6c4fd9f740f5d22a0812784d3d35ce8458f8cbe1c35812c15c&amp;scene=21#wechat_redirect\" data-itemshowtype=\"0\" tab=\"innerlink\" style=\"text-decoration: underline;\" data-linktype=\"2\" rel=\"noopener noreferrer\">\u4ec0\u4e48\u662f\u6f14\u5316\u7b97\u6cd5 | \u96c6\u667a\u767e\u79d1<\/a><\/p>\n<p><a target=\"_blank\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzIzMjQyNzQ5MA==&amp;mid=2247530452&amp;idx=2&amp;sn=bb2ef8b913fd2d847493d37148e48850&amp;chksm=e8972d59dfe0a44fa8129c9a537309d26f8473ddc9de79ca7af85e5e7e7e50e56179097423be&amp;scene=21#wechat_redirect\" data-itemshowtype=\"0\" tab=\"innerlink\" style=\"text-decoration: underline;\" data-linktype=\"2\" rel=\"noopener noreferrer\">\u4ec0\u4e48\u662f\u7cd6\u57df\u6a21\u578b | \u96c6\u667a\u767e\u79d1<\/a><\/p>\n<p><a target=\"_blank\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzIzMjQyNzQ5MA==&amp;mid=2247528171&amp;idx=3&amp;sn=934504d59508673ec5af7d49398b6058&amp;chksm=e8973466dfe0bd7035db14e734874916b9b4147596f02851955ed136f9a6d442078943168a07&amp;scene=21#wechat_redirect\" data-itemshowtype=\"0\" tab=\"innerlink\" style=\"text-decoration: underline;\" data-linktype=\"2\" rel=\"noopener noreferrer\">\u4ec0\u4e48\u662f\u8774\u8776\u6548\u5e94 | \u96c6\u667a\u767e\u79d1<\/a><\/p>\n<p><a target=\"_blank\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzIzMjQyNzQ5MA==&amp;mid=2247534064&amp;idx=3&amp;sn=47b5ff3eaef0488ce7ac4f0eb5a29f32&amp;chksm=e8971f7ddfe0966b6bbe163fc72db861ad08645e2edb7df44d0751e3a8eb329f59a8f0b856fb&amp;scene=21#wechat_redirect\" data-itemshowtype=\"0\" tab=\"innerlink\" data-linktype=\"2\" style=\"text-decoration: underline;\" rel=\"noopener noreferrer\">\u4ec0\u4e48\u662f\u90bb\u63a5\u8868 | \u96c6\u667a\u767e\u79d1<\/a><br \/><a target=\"_blank\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzIzMjQyNzQ5MA==&amp;mid=2247502752&amp;idx=1&amp;sn=4ceaf4f227a4f7065b3cd256a2022552&amp;chksm=e897912ddfe0183b570a12e6b40212e33b76a95c54abe6e10afe7069acb9f6236bd39ccf8cda&amp;scene=21#wechat_redirect\" textvalue=\"\u52a0\u5165\u96c6\u667a\uff0c\u4e00\u8d77\u590d\u6742\uff01\" data-itemshowtype=\"0\" tab=\"innerlink\" data-linktype=\"2\" hasload=\"1\" rel=\"noopener noreferrer\">\u52a0\u5165\u96c6\u667a\uff0c\u4e00\u8d77\u590d\u6742\uff01<\/a><\/p>\n<p>\u70b9\u51fb\u201c\u9605\u8bfb\u539f\u6587\u201d\uff0c\u9605\u8bfb\u9e1f\u7fa4\u7b97\u6cd5\u76f8\u5173\u5185\u5bb9\u4e0e\u53c2\u8003\u6587                 <\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u201c\u96c6\u667a\u767e\u79d1\u7cbe\u9009\u201d\u662f\u4e00\u4e2a\u957f\u671f\u4e13\u680f\uff0c\u6301\u7eed\u4e3a\u5927\u5bb6\u63a8\u9001\u590d\u6742\u6027\u79d1\u5b66\u76f8\u5173\u7684\u57fa\u672c\u6982\u5ff5\u548c\u8d44\u6e90\u4fe1\u606f\u3002\u4f5c\u4e3a\u96c6\u667a\u4ff1\u4e50\u90e8\u7684\u5f00\u6e90\u79d1\u5b66\u9879\u76ee\uff0c\u96c6\u667a\u767e\u79d1\u5e0c\u671b\u6253\u9020\u590d\u6742\u6027\u79d1\u5b66\u9886\u57df\u6700\u5168\u9762\u7684\u767e\u79d1\u5168\u4e66\uff0c\u6b22\u8fce\u5bf9\u590d\u6742\u6027\u79d1\u5b66\u611f\u5174\u8da3\u3001\u70ed\u7231\u77e5\u8bc6\u6574\u7406\u548c\u5206\u4eab\u7684\u670b\u53cb\u52a0\u5165\uff01 \u672c\u6587\u662f\u5bf9\u96c6\u667a\u767e\u79d1\u4e2d\u201c\u9e1f\u7fa4\u7b97\u6cd5\u201d\u8bcd\u6761\u7684\u6458\u5f55\uff0c\u53c2\u8003\u8d44\u6599\u53ca\u76f8\u5173\u8bcd\u6761\u8bf7\u53c2\u9605\u767e\u79d1\u8bcd\u6761\u539f\u6587\u3002\u672c\u8bcd&#8230;<\/p>\n","protected":false},"author":1,"featured_media":24054,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"special":[],"_links":{"self":[{"href":"https:\/\/swarma.org\/index.php?rest_route=\/wp\/v2\/posts\/24063"}],"collection":[{"href":"https:\/\/swarma.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swarma.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swarma.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swarma.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=24063"}],"version-history":[{"count":0,"href":"https:\/\/swarma.org\/index.php?rest_route=\/wp\/v2\/posts\/24063\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swarma.org\/index.php?rest_route=\/wp\/v2\/media\/24054"}],"wp:attachment":[{"href":"https:\/\/swarma.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=24063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swarma.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=24063"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swarma.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=24063"},{"taxonomy":"special","embeddable":true,"href":"https:\/\/swarma.org\/index.php?rest_route=%2Fwp%2Fv2%2Fspecial&post=24063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}