Converting an equation into a quadratic polynomial in terms of time

312 Views Asked by At

I was trying to do some collision detection between discs for a physics simulation program I was doing. I had arrived at the equation:

Object1Coordinate + (time$\cdot$Object1Velocity) = Object2Coordinate + (Time$\cdot$Object2Velocity)

I gave this to a friend to help me turn this into an equation where I could solve for time.

He came up with:

($t^2$)(magnitude of vector between the two velocities$)^2 + 2t$(dot product between the coordinates and velocities delta) + (magnitude of vector of the difference between the two coordinates)$^2$

How did he get to this quadratic formula?

I'm sorry for the bad formatting, I don't know how to use the math notation. If anyone would like to help me format the question properly I would be thankful

1

There are 1 best solutions below

3
On BEST ANSWER

Your friend likely started with the vector equation: $$ \Delta x + t \Delta v = \vec 0, $$ where $\Delta x$ is the (vector) difference of coordinates and $\Delta v$ is the difference of velocities, then used the fact that $\vec v = \vec 0$ iff $\|\vec v\|^2 = \vec v \cdot \vec v = 0$, so the equation is equivalent to $$(\Delta x + t \Delta v)\cdot(\Delta x + t \Delta v) = (\Delta x \cdot \Delta x) + 2t (\Delta x \cdot \Delta v) + t^2 (\Delta v \cdot \Delta v)\\ = \|\Delta x\|^2 + 2t (\Delta x \cdot \Delta v) + t^2 \|\Delta v\|^2 = 0.$$

However, it makes little sense to literally solve this equation as written (I notice that the OP doesn't actually specify that the RHS is zero): as hardmath points out a quadratic is not really necessary since by geometric considerations the quadratic is either strictly positive (if there is no intersection), or it has a double-root at the unique solution (with one exception: if $\Delta v = \Delta x = \vec 0$ then it's identically zero), so solving the quadratic directly is silly.

However, finding the unique critical point of the quadratic corresponds to minimizing the distance between the two objects. That value of $t_c = -\|\Delta v\|^2 / (\Delta x \cdot \Delta v)$ is the least-squares approximate solution to the overconstrained system $\Delta x + t \Delta v = \vec 0$.