2d 刚体物理引擎

Ivan Lv6

PBD Position Based Dynamics

一个物理引擎伪代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
while simulation:
for all particles i:
// update transformation integration
v_i = v_i + g * dt
p_i = x_i // save previous position
x_i = x_i + v_i * dt

// update rotation integration
q_prev = q
w = w + h * I.inverse * tau
q = q + 1/2 * h * v[w_x, w_x, w_x, 0] q

for all constraints C:
solve(C, dt)

for all particles i:
v_i = (x_i - p_i) / dt


// solve improper disorder
def solve(C, dt):
for all particles i in C:
compute dx_i
x_i = x_i + dx_i
  • Title: 2d 刚体物理引擎
  • Author: Ivan
  • Created at : 2026-09-23 00:00:00
  • Updated at : 2026-10-23 18:02:31
  • Link: https://ivanfan-van.github.io/2026/09/23/note-2-seed-001/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
2d 刚体物理引擎