Free JavaScript Editor Ajax Editor

↑

Main Page

## Moving TestsImagine a game of snooker with balls moving around quickly. If we need to compute the interactions between the different balls efficiently and with precision, we cannot consider them to be static objects. We need to compute trajectories, making sure we detect both if a collision took place and when it took place. This is a relatively young field and only recent advances in real-time physics have made such computations possible. ## Sphere: SphereWe will now derive a test for moving spheres, which is very useful for moving objects. I will use it as an example of how to solve algebraic, restriction-based equations so we can compute collisions. You can adapt the following case for other shapes as well. To begin with, here are the two expressions for two points moving in space. Each point is determined by its position when time=0 and its velocity vector: pos Now, we can blend the two equations by computing the difference between them, that is, the vectorial difference between both positions: pos Now, let's square the equation: dpos Expanding it to incorporate the X, Y, and Z terms, we get the following expression for the distance between the two sphere centers: dist = sqrt (dpos0.x Figure 22.7 illustrates the situation described by the preceding equation. By grouping terms together, we reach the following expression: dist = sqrt ( A + B*t + C*t where A = dpos.x ## Figure 22.7. Moving sphere test.If we forget about dist, and square both sides of the equation to compute dist squared instead, we get dist Now, let's incorporate the radii to check for a collision. A collision happens if, for any moment in time dist = r1 + r2 where dist is the distance we were just working on, and r1/r2 are the radii. Now, let's square the equation: dist This can now be blended with our earlier equation to produce (r1+r2) By rearranging terms so this equation fits with our quadratic solving formulas from school, we get C*t or C*t Assuming a change in the value of A, which right now is A = dpos.x The equation is solved by t = -B +/- sqrt (B So there is a collision if B Then, we assume B The solution is that the collision occurs if the following is true: 4*(dpos dot dv) (dpos dot dv) |

↓

Ajax Editor JavaScript Editor