-
Notifications
You must be signed in to change notification settings - Fork 0
Contactformula
times = ( +/-Sqrt( (d*d-P·P)*V·V + V·P*V·P ) -V·P ) / V·V
Thanks to one Joshua de Bellis who worked out this equation for me after I petitioned him randomly in a library - to look at my tricky notes! He explained the trick was to think about vectors. The solution which he generated using mathematica (the softwar) is closely related to 'the raycasting formula' commonly used in raycasting and in collision detection programming, only it is more concise than commonly described.
Here are my naive thoughts on the formula:
Expression:
( +/-Sqrt( (d*d-P·P)*V·V + V·P*V·P ) -V·P ) / V·V`
d : sum of two particles contact-radii
P : delta of two particles position vectors at t=0
V : delta of velocity vectors
Summed-squares or dot-products:
(d*d-P·P)
Contact-radii minus difference of position at t=0
*V·V
Sum of squares of dimensions of the delta velocity
vector (position change per t) (squared)
V·P
This seems to give the distance to the spheres
minima of separation, squared, yet signed (neat).
This distance might exist in the spheres 'delta-space'
between the origin ([0,0,0] : where Pa resides) and where
Pb resides at the minima - the point of its travel which is
closest to Pa. Because it is in 'delta-space' Pa does not travel,
but this hypoteneus between the origin and Pbs position in
delta-space is the same as the separation between them in real-space.
V·P / V·V
would be the time taken to make that journey to 'the minima'
This is the squared distance between the objects at t=0 and their earliest contact:
0 - Sqrt( (d*d-P·P)*V·V + V·P*V·P ) -V·P
Same at their lastest contact:
0 + Sqrt( (d*d-P·P)*V·V + V·P*V·P ) -V·P
This must be length (through delta space not time) of their contact:
Sqrt( (d*d-P·P)*V·V + V·P*V·P ) //an absolute value
In places it gets called 'the determinant' ,when it is negative, there is no contact between the spheres and no way to proceed with slow square root operation. (except modern cpu fsqrt is not much slower than division)
(d*d-P·P)*V·V + V·P*V·P
In other physics engine source code i have seen this wrapped
up with unneccessary workings of x=-b+-sqrt(4ac)
Why does multiplying the delta-pos of Pb by its delta-vel give its minima from the origin 'sign-squared' ?