小编shi*_*shi的帖子

我的行星疯了 - 一个与Java有关的问题

今天早上我想写一个无用的程序,我最终得到了这个极其简单的天文模拟器.MCVE版本的代码附在帖子的末尾.

然后我添加了一些行星,坐下来准备好欣赏一些绕着彼此绕行的行星.然而事实证明是一个问题.

问题是,两个原本相互靠得太近的静态行星往往会相互冲击到超高速,它们都会永远消失在屏幕之外.这显然违背了动力原则.行星不这样做.我开始怀疑我的牛顿法实施有什么问题.但有些时候,只要它们保持"安全"距离,行星就可以正常工作.

如果你想研究这个问题,我已经为你仔细考虑了两个设置.第一个,增加了两个行星,并且非常稳定.(您可以通过注释掉其中包含'Three'的每一行来完成此操作.)您可以通过输入默认代码来测试第二行.这是行星疯狂的地方.

这个问题似乎是一个谜,起源于我从未探索过的一些计算机科学领域(尽管我是一个菜鸟).为了我的头发,如果有人能解释,我会非常感激.

代码开头:

PVector planetOneLocation = new PVector(300, 200);
PVector planetOneSpeed = new PVector(0, -.1);
float planetOneMass = 1;

PVector planetTwoLocation = new PVector(100, 200);
PVector planetTwoSpeed = new PVector(0, .1);
float planetTwoMass = 1;

PVector planetThreeLocation = new PVector(200, 200);
PVector planetThreeSpeed = new PVector(0, 0);
float planetThreeMass = 10;

float g = 5;

void setup() {
  size(500, 500);
}

void draw() {

  updatePlanetOne();
  updatePlanetTwo();
  updatePlanetThree();

  planetOneLocation.add(planetOneSpeed);
  planetTwoLocation.add(planetTwoSpeed);
  planetThreeLocation.add(planetThreeSpeed);

  background(0);

  ellipse(planetOneLocation.x, planetOneLocation.y, 10*planetOneMass, 10*planetOneMass); …
Run Code Online (Sandbox Code Playgroud)

processing physics

7
推荐指数
1
解决办法
214
查看次数

标签 统计

physics ×1

processing ×1