星星下落

To humans, stars are among the most reliable facts of life. Our main star, the Sun, was there on the day we were born and will be there on the day we die. And the same is true for almost every other star we can observe in the evening sky. Yes, the occasional star may go “poof” as a supernova, but by and large, the stars in the sky do not change much during our lifetimes. You can set your clocks by them, literally.

对人类而言,恒星是生命中最可靠的事实之一。 我们的主要恒星太阳在我们出生的那一天就在那里,并且在我们死亡的那一天会在那里。 我们几乎可以在傍晚的天空中观察到的所有其他恒星也是如此。 是的,偶尔的恒星可能会像超新星一样“变弱”,但总的来说,天空中的恒星在我们的一生中不会发生太大变化。 您可以从字面上设置时钟。

On longer timescales, stars get around though. Every star is constantly nudged gravitationally by a tiny amount by all the stars around it. Stars that are close have a large effect, but huge amounts of stars farther away also play a role. And even mysterious “dark matter” affects how stars move relative to one another.

在更长的时间尺度上,恒星会绕行。 每颗恒星在重力作用下都会不断被周围的所有恒星微移。 靠近的恒星具有很大的影响,但是距离较远的大量恒星也起作用。 甚至神秘的“暗物质”也会影响恒星彼此相对运动的方式。

A few years ago, astrophysicist & research programmer at Wolfram|Alpha, Jeffrey Bryant, wrote a blog post about a really interesting simulation of colliding galaxies with each galaxy containing billions of stars. That post includes the complete Wolfram Language code to recreate the full simulation shown here:

几年前,Wolfram | Alpha的天体物理学家和研究程序员Jeffrey Bryant撰写了一篇博客文章,内容涉及一个非常有趣的模拟碰撞星系,每个星系包含数十亿颗恒星。 该帖子包括完整的Wolfram语言代码,以重新创建此处显示的完整模拟:

演示地址

Colliding galaxies are an interesting example of a type of emergent behavior, where tiny individual objects respond to typically small outside influences. Another good example of this behavior is a flock of birds, where each bird individually responds to changes in the flight direction of the birds around itself.

碰撞星系是一种新兴行为的有趣示例,其中微小的单个物体对通常很小的外部影响做出响应。 这种行为的另一个很好的例子是一群鸟,其中每只鸟分别对自己周围鸟的飞行方向的变化做出React。

Yasong Zhou on 雅松周上UnsplashUnsplash

Simulating some of these emergent behaviors can be done with surprisingly simple code in the Wolfram Language. My Wolfram Language example is loosely based on a Wolfram Community post by Simon Woods. It considers a number of objects on a flat surface, let’s call them particles, which interact with each other. Every particle has one “friend” and it always wants to move in the direction of this friend wherever it is on the plane. Every particle also has one “enemy” and it always wants to move away from this enemy. Then, every so often, a particle may randomly get a new friend and a new enemy. This helps to keep the emergent behavior interesting and dynamic. Finally, each particle wants to slowly drift to the center of the plane. This rule keeps the particles slowly drifting away from the center.

可以使用Wolfram语言中出乎意料的简单代码来模拟其中一些紧急行为。 我的Wolfram语言示例大致基于Simon Woods的Wolfram社区帖子。 它考虑了平面上的许多对象,我们称它们为粒子,它们彼此相互作用。 每个粒子都有一个“朋友”,无论它在飞机上的任何地方,它总是想朝这个朋友的方向移动。 每个粒子也都有一个“敌人”,它总是想远离这个敌人。 然后,每隔一段时间,粒子可能会随机地遇到一个新朋友和一个新敌人。 这有助于保持紧急行为的趣味性和动态性。 最后,每个粒子都希望缓慢地漂移到平面的中心。 该规则使粒子缓慢地偏离中心。

That’s a lot of rules, but simple to program in the Wolfram Language once you break it down. Let’s start by picking the number of particles and start with 1,000:

这是很多规则,但是一旦分解就可以使用Wolfram语言进行编程。 让我们从选择粒子数开始,并从1,000开始:

n = 1000

Next, we generate n random particles on the plane with coordinates in the range (-1,1) x ( -1,1):

接下来,我们在平面上生成n个随机粒子,坐标范围为(-1,1)x(-1,1):

x = RandomReal[{-1, 1}, {n, 2}]

Each particle has a friend and an enemy. We generate them in one go with the following line of code. The list p contains the list of friends for each particle and the list q contains the list of enemies:

每个粒子都有一个朋友和一个敌人。 我们使用以下代码一次性生成它们。 列表p包含每个粒子的朋友列表,列表q包含敌人列表:

{p, q} = RandomInteger[{1, n}, {2, n}]

For example, p may start with {621, 47, 874, …} which means that the first particle in x is friends with the 621st particle in x and so on.

例如,p可与开始{621,47,874,...}这意味着在x中的第一粒子是朋友与第六百二十一粒子在x和等。

The magnitude of the force of attraction or repulsion depends on the distance between a particle and its friend or enemy. The following function f is using a very compact Wolfram Language notation to calculate the forces for all particles in one go:

吸引或排斥力的大小取决于粒子与其朋友或敌人之间的距离。 以下函数f使用非常紧凑的Wolfram语言符号来一次计算所有粒子的力:

f = Function[{x, i}, (#/(.01 + Sqrt[#.#])) & /@ (x[[i]] - x)]

To update each particle for one time step, we use the following code. The first term 0.995 x represents the drift of the particles towards the center of the plane. The second term represents the attracting force, with a parameter of 0.02 specifying how strong the overall attraction is. The last term represents the repulsive force. It works the same as the attractive force, but in the opposite direction

要更新每个粒子一个时间步长,我们使用以下代码。 第一项0.995 x表示粒子向平面中心的漂移。 第二项表示吸引力,参数0.02指定总体吸引力的强度。 最后一项代表排斥力。 它的作用与吸引力相同,但方向相反

x = 0.995 x + 0.02 f[x, p] - 0.01 f[x, q]

Finally, every time step runs the following conditional statement. It is True about 10% of the time and when that happens a single particle is assigned a new friend and enemy:

最后,每个时间步都运行以下条件语句。 大约有10%的时间是正确的,并且当这种情况发生时,会为单个粒子分配一个新的朋友和敌人:

If[ RandomReal[] < 0.5, With[{r1 = RandomInteger[{1, n}]},   p[[r1]] = RandomInteger[{1, n}];  q[[r1]] = RandomInteger[{1, n}]]]

To visualize the particles we use a basic Graphics object to display the particles as white points. The Dynamic expression detects if any variables change inside its scope and it re-evaluates if it does. It is essentially a smart while-true loop that you can place anywhere in rendered typeset code:

为了可视化粒子,我们使用基本的Graphics对象将粒子显示为白点。 动态表达式会检测其范围内是否有任何变量更改,并重新评估其是否更改。 从本质上讲,这是一个智能的while-true循环,您可以将其放置在呈现的排版代码中的任何位置:

Graphics[{ White, PointSize[0.007], Dynamic[  If[RandomReal[] < 0.1,    With[{r1 = RandomInteger[{1, n}]}, p[[r1]] = r; q[[r1]] = r]  ];  Point[x = 0.995 x + 0.02 f[x, p] - 0.01 f[x, q]] ]},  PlotRange -> {{-1, 1}, {-1, 1}},  Background -> Black, ImageSize -> 600]

The end result can be seen directly in a Wolfram Notebook (it will play until you choose to stop it) or in the following one minute video that I created for YouTube:

最终结果可以直接在Wolfram笔记本中看到(直到您选择停止它为止,它会一直播放)或在我为YouTube创建的以下一分钟视频中:

演示地址

It’s always quite amazing how a tiny amount of code can yield such intricate behavior. There are lots of interesting ways to create variations, which I hope to explore in a future post. For example, each particle can have multiple friends and enemies and, instead of rendering with simple white points, one could use arbitrary graphics (circles, polygons) to make things even more bizarre-looking.

很少的代码可以产生如此复杂的行为总是令人惊讶。 有很多有趣的方式可以创建变体,我希望在以后的文章中对此进行探讨。 例如,每个粒子可以有多个朋友和敌人,而不是使用简单的白点进行渲染,而可以使用任意图形(圆形,多边形)使事物看起来更加离奇。

翻译自: https://towardsdatascience.com/dancing-with-the-stars-aded5e9b3f3c

星星下落


http://www.taodudu.cc/news/show-4495898.html

相关文章:

  • 11.拼数(c++)
  • 平均数,初学
  • 拿数问题II
  • FZU2109 数位dp 含前导零
  • 树状数组的进阶运用(Stars 数星星)
  • 2020.5.9测试 T3 数星星
  • URAL 1028 数星星 题解
  • 我对于互联网发展的看法和一些理解
  • 中国互联网发展总结
  • 计算机网络(2)--- 因特网的发展阶段与组织
  • 网络层协议(1):Internet 发展简史(上)
  • 因特网的发展大致分为哪几个阶段?请指出这几个阶段的主要特点。
  • 因特网的发展历程
  • python泰坦尼克号生存预测论文_用Python预测泰坦尼克号生存情况
  • python泰坦尼克号案例分析_Python机器学习案例-泰坦尼克之灾
  • Keras神经网络实现泰坦尼克号旅客生存预测
  • kaggle 泰坦尼克事件——随机森林算法实现
  • 贝叶斯网络python实战(以泰坦尼克号数据集为例,pgmpy库)
  • Matlab粒子群算法神经网络泰坦尼克号
  • Matlab遗传算法神经网络泰坦尼克号
  • 利用tensorflow神经网络进行泰坦尼克的生存预测
  • 机器学习算法源码
  • python机器学习算法-Chapter1
  • 《python 机器学习算法-logistics regression》
  • python3.6实现随机森林算法(可视化)机器学习算法(赵志勇)学习笔记
  • 11-赵志勇机器学习-DBSCAN聚类
  • 01-赵志勇机器学习-Logistics_Regression-train
  • 10-赵志勇机器学习-meanshift
  • 02-赵志勇机器学习-Logistics_Regression-test(转载)
  • 09-赵志勇机器学习-k-means

星星下落_与星星共舞相关推荐

  1. Matlab 斜率和曲率,曲率_与闪电共舞_新浪博客

    就是弯曲程度. 曲线的曲率(curvature)就是针对曲线上某个点的切线方向角对弧长的转动率,通过微分来定义,表明曲线偏离直线的程度.曲率越大,表示曲线的弯曲程度越大. 我们有时候也说曲率半径(曲率 ...

  2. java星星随机下落_随机显示星星(点击可删除)

    随机显示星星 //实例:随机显示小星星 /*(1)网页加载完成,背景颜色为黑色 (2)创建图片节点,并追加到body父节点下 (3)定时器 (4)星星随机大小 (5)星星随机定位 (6)单机星星,星星 ...

  3. java满天星星代码_满天星空的代码实现

    #include #include #include #include using namespace std; #define RGB_AMOUNT250 //颜色数量 #define SCREEN ...

  4. 与ObjectDataSource共舞

    4,ORM组件XCode(与ObjectDataSource共舞) XCode为了能更方便的解决大部分问题,不得不"屈身"于ObjectDataSource. 先上一个经典例子(O ...

  5. 谷歌参展攻略!AI皮影戏、3D作画、与AI共舞...嗨翻魔都(附视频)

    来源:大数据文摘 作者:睡不着的Iris.魏子敏 本文约3200字,建议阅读8分钟. 本文介绍了谷歌在上海举办艺术展,带领大家看看如何将人工智能和绘画.音乐和皮影戏全面结合起来. 谷歌来上海啦! 虽然 ...

  6. “云计算”三部曲之二:与“云”共舞——再谈云计算

    引言:去年,我曾在一篇名为<未来计算在"云-端">的文章中指出,纯"云计算"并不是启动计算未来的"万能钥匙","云+端 ...

  7. mongodb与java结合_MongoDB初探系列之四:MongoDB与Java共舞

    MongoDB初探系列之四:MongoDB与Java共舞 来源:互联网 作者:佚名 时间:2015-08-05 08:20 对各位注意到这个帖子的朋友说一声对不起,我不是故意的测试服务器一直没关,一忙 ...

  8. 与毒”共舞30年!清华美女研究生为何放弃高薪,选择特招入伍?背后的原因令人泪崩......

    全世界只有3.14 % 的人关注了 爆炸吧知识 从武汉新冠疫情爆发到如今,陈薇没有一天休息.短短半年间,54岁的她头发从黑到白,也哭了好几次. 刚去武汉-现在 陈薇的母亲也在电视上看到了女儿的变化:& ...

  9. 雨林木风与微软数年博弈:蚂蚁和大象共舞

    http://www.cnbeta.com/articles/105232.htm 虎年春节刚过,雨林木风公司位于松山湖的新大楼内,装修工人们又忙碌了起来. 雨林木风, 曾被业界称为"三大X ...

最新文章

  1. Linux那些事儿 之 戏说USB(13)接口是设备的接口(二)
  2. 发现错误(Core Data 应用程序实践指南)
  3. python可以调试吗_调试-有什么好的方法可以使我的Python代码首次运行?
  4. GacUI学习(一)
  5. 反思项目调试整体过程
  6. java 两个页面传递数据,请问Cookie怎么在两个页面间传递数据?
  7. java中为final变量赋值的几种方式
  8. Linux的下载命令wget详解
  9. 使用PDF-XChange Editor为PDF文件添加图章(仅图片)
  10. 微积分8--相关变化率
  11. 自己动手,在macOS High Sierra中编译一个可debug的JDK
  12. 快速突破面试算法之二分查找篇
  13. 【软件下载】Axure10正式版(含汉化包)
  14. c语言 牛顿方法计算平方根,sqrt()平方根计算函数的实现2——牛顿迭代法
  15. 计算机wifi共享,win7 wifi共享,教您Win7如何设置wifi共享
  16. 【word】页码分栏,左侧文字右侧页码
  17. php 腾讯云 短信验证码发送
  18. python打印七段数码管引脚图_前辈学51单片机的感悟是怎么样的?说说看
  19. float.h中DBL_TRUE_MIN的定义和作用
  20. top和margin-top等的区别

热门文章

  1. nuxt百度地图引入基础使用,百度地图初始化,行政区划划分
  2. 2021-2022-1 ACM集训队每周程序设计竞赛(5) - 问题 C: 剪切 - 题解
  3. linux 驱动笔记(四)
  4. matlab fitctree 原理,电力窃漏电用户自动识别.PDF
  5. LeetCode70. 爬楼梯(Java解法——使用完全背包求解)
  6. Typo: In word 拼写检查
  7. 获刑2年半!大学生利用漏洞免费吃肯德基,还把“方法”分享给同学
  8. 选择明文攻击和选择密文攻击
  9. java格式化金额千位数,java金额格式化解决思路
  10. 目前国际上存在的主要安全标准