如何使用中点方法积分粒子

问题描述 投票:1回答:1

我正在使用Euler方法对物理引擎中的粒子进行数值积分。

float inverseMass;
Vector3 position, velocity;
Vector3 sumForces, gravity, inputForce;
void Particle::Integrate(float dt) {
   sumForces = (gravity+inputForce)*dt;
   Vector3 a = sumForces*inverseMass;
   velocity += a;
   position += velocity*dt;
}

我想用Midpoint方法实现更好的集成器。基于此过程https://www.cs.cmu.edu/~baraff/pbm/constraints.pdf,使用中点方法,您将执行一个完整的欧拉步骤,然后评估中点对粒子的作用力,然后使用该中点值进行一个步骤。

enter image description here

我执行了第一步。

void Particle::Integrate(float dt) {
   //Take full Euler step
   Vector3 sumForces = (gravity+inputForce)*dt;
   Vector3 a = sumForces*inverseMass;
   Vector3 tempVelocity = a+velocity;
   Vector3 deltaX += tempVelocity*dt;

   Vector3 midpoint = deltaX + position;

}

不过我如何从这里继续?如何计算中点的力?我是否只是在半个时间步长进行计算,但是计算中点位置的目的是什么?

c++ integration numerical-methods physics-engine
1个回答
1
投票

您必须考虑到您的状态包含两个主要成分,位置x和速度v。该方法必须针对完整状态统一制定,

dx1 = v*dt,           dv1 = acc(t,x,v)*dt
dx2 = (v+0.5*dv1)*dt, dv2 = acc(t+0.5*dt, x+0.5*dx1, v+0.5*dv1)*dt

x = x + dx2,          v = v+dv2.

已经从基本原理上写下了公式,现在您可以看到消除dx向量相对容易。因此仍然需要计算

dv1 = acc(t,x,v)*dt,
dv2 = acc(t+0.5*dt, x+0.5*v*dt, v+0.5*dv1)*dt,
x = x + (v+0.5*dv1)*dt,
v = v + dv2
© www.soinside.com 2019 - 2024. All rights reserved.