Use a different "approaching" function to fix the "sticky balls" bug.#2
Open
martinodb wants to merge 9 commits intogtrak:masterfrom
Open
Use a different "approaching" function to fix the "sticky balls" bug.#2martinodb wants to merge 9 commits intogtrak:masterfrom
martinodb wants to merge 9 commits intogtrak:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ;)