【发布时间】:2018-09-21 16:30:18
【问题描述】:
我正在处理一个简单的重力程序。我的程序采用粒子并根据重力公式将它们相互吸引。不幸的是,一旦我尝试将力与PVector.mult() 相乘,我就会在标题中看到错误:
无法在基本类型 float 上调用 mult(float)。
这是我的方法代码。 G 在别处定义。
public float distance(Particle other) {
return location.sub(other.location).mag();
}
public PVector direction(Particle other) {
return location.sub(other.location).normalize();
}
public void gravity(Particle other) {
float grav = (G*((mass * other.mass)/pow(distance(other), 2)));
if(distance(other) != 0) {
acceleration.add(distance(other).mult(grav));
}
为什么我不能通过一个浮点数到期的浮点数?
【问题讨论】:
-
您能发一个minimal reproducible example 让我们自己复制粘贴来查看错误吗?
标签: parameter-passing processing