Skip to content

Use a different "approaching" function to fix the "sticky balls" bug.#2

Open
martinodb wants to merge 9 commits intogtrak:masterfrom
martinodb:master
Open

Use a different "approaching" function to fix the "sticky balls" bug.#2
martinodb wants to merge 9 commits intogtrak:masterfrom
martinodb:master

Conversation

@martinodb
Copy link

Hello :)

OK, as you see, the main change is in the "approaching" function. I think the original one would sometimes mistakenly think that two balls were approaching when they had gone slightly past each other, because it only looks at the signs of the velocities. So I replaced it with one that also depends on the positions, and it seems to have fixed the problem (needs confirming!).

The reasoning for my version of the approaching function is as follows:

Let r1, r2 be two rigid bodies, D12 is the distance between them, xr1 (= [xr11,xr12] ) and xr2 (= [xr21, xr22]) their respective position vectors, vr1 (= [vr11, vr12]) and vr2 (= [vr21, vr22]) their respective velocity vectors,

then we say they are approaching iff d(D12)/dt is negative.

D12 = sqrt ((xr11 - xr21)^2 + (xr12 - xr22)^2) = sqrt (K1), where K1 is always possitive.

d(D12)/dt = (1/2) * K1 ^ (-1/2) * dK1/dt
0 > d(D12)/dt => 0 > dK1/dt (since K1 is possitive, we can remove it without affecting the sign)
0 > 2 * (xr11 - xr21) * (vr11 - vr21) + 2 * (xr12 - xr22) * (vr12 - vr22)
0 > (xr11 - xr21) * (vr11 - vr21) + (xr12 - xr22) * (vr12 - vr22)

0 > (xr1 - xr2) DotProduct (vr1 - vr2)

QED ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant