how did he do that ?

Started by
7 comments, last by unbird 9 years, 5 months ago

Iv'e read an article about collision dectection , and there was one thing I did not understand :

from this

kwq3xmdohzzu.png

to this :

mlk1j02nynqd.png

how did he do that ?

Advertisement

That's a linear system with ua and ub as variables. You can solve it in different ways and reach the same expression or an equivalent one.

In this case it looks like it's solved using the Cramer's rule: http://mathworld.wolfram.com/CramersRule.html

I guess it doesn't really matter the step by step solution, it won't make much difference to your programming knowledge. If you're learning about collision detection don't waste too much time on stuff like that, there are much more usefull concepts involved.

To echo the guy above me: often times you can solve collision detection problems by writing down functions and solving them, but that usually gives nothing back to the developer in terms of geometric intuition. Sometimes the geometric approach can lead to simpler or alternative (optimized) solutions.


how did he do that ?

I'm with you. I hate it when I'm using an algorithm that I don't understand. I have run into many stumbling blocks in the "Real Time Rendering" equations where there are giant leaps in math without any explanation. I like to know how they got from A to B. It is of no use when you're just coding, but when you are trying to lean how someone came up with the algorithm, giant leaps in math with no explanation doesn't help.

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

That's a linear system with ua and ub as variables. You can solve it in different ways and reach the same expression or an equivalent one.

In this case it looks like it's solved using the Cramer's rule: http://mathworld.wolfram.com/CramersRule.html

I guess it doesn't really matter the step by step solution, it won't make much difference to your programming knowledge. If you're learning about collision detection don't waste too much time on stuff like that, there are much more usefull concepts involved.

To echo the guy above me: often times you can solve collision detection problems by writing down functions and solving them, but that usually gives nothing back to the developer in terms of geometric intuition. Sometimes the geometric approach can lead to simpler or alternative (optimized) solutions.


how did he do that ?

I'm with you. I hate it when I'm using an algorithm that I don't understand. I have run into many stumbling blocks in the "Real Time Rendering" equations where there are giant leaps in math without any explanation. I like to know how they got from A to B. It is of no use when you're just coding, but when you are trying to lean how someone came up with the algorithm, giant leaps in math with no explanation doesn't help.

I really need to understand this for implementing something similar

But are you going to implement the middle steps too?

Try applying the Cramer's rule and you'll probably get that same result, in that link I quoted there's a step by step description of the method.

If you want a simpler to understand method that doesn't involve determinants and works for 2 equations, try this:

  1. Isolate ua form the first equation and replacing it into the second one.
  2. With that new equation you should be able to get the ub value on the book or some equivalent expression.
  3. Knowing ub replace it into the first equation and you can get obtain the value of ua (or, again, an equivalent expression).

That method uses less concepts, but you can easily mess up with all those coeficients.


That method uses less concepts, but you can easily mess up with all those coeficients.

I started this on my whiteboard. Yuck. Stick with the above suggestions!

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

If the book's primary concern is not teaching math, I think that step is perfectly fine. It is not trying to teach you how to solve a linear system of equations, it's just solving one. You can learn about how you solve systems of equations elsewhere, and then you can check that you get the same result.

Time to put that LaTeX renderer to the test (I hope you got a big monitor)

With Diego's suggestions:

\begin{matrix}
x_{A_1}+u_a(x_{A_2}-x_{A_1}) = x_{B_1} + u_b(x_{B_2}-x_{B_1}) & |& -x_{A_1} \\
u_a(x_{A_2}-x_{A_1}) = x_{B_1} -x_{A_1} + u_b(x_{B_2}-x_{B_1}) & |& divide\ by \ (x_{A_2}-x_{A_1}) \\
u_a = \frac{x_{B_1} -x_{A_1} + u_b(x_{B_2}-x_{B_1})}{(x_{A_2}-x_{A_1})} & | & replace \ in \ 2nd \ equation \\
y_{A_1}+\frac{x_{B_1} -x_{A_1} + u_b(x_{B_2}-x_{B_1})}{(x_{A_2}-x_{A_1})}(y_{A_2}-y_{A_1}) = y_{B_1} + u_b(y_{B_2}-y_{B_1}) &|& -y_{B_1} \\
y_{A_1}-y_{B_1}+\frac{x_{B_1} -x_{A_1} + u_b(x_{B_2}-x_{B_1})}{(x_{A_2}-x_{A_1})}(y_{A_2}-y_{A_1}) = u_b(y_{B_2}-y_{B_1}) &|& multiply \ by \ (x_{A_2}-x_{A_1}), \ and\ some\ grouping \\
(y_{A_1}-y_{B_1})(x_{A_2}-x_{A_1})+ (x_{B_1} -x_{A_1} + u_b(x_{B_2}-x_{B_1}))(y_{A_2}-y_{A_1}) = u_b(y_{B_2}-y_{B_1})(x_{A_2}-x_{A_1}) & | & multiply\ out\ 2nd\ term\ on\ the\ left, \\
(y_{A_1}-y_{B_1})(x_{A_2}-x_{A_1})+ (x_{B_1} -x_{A_1})(y_{A_2}-y_{A_1}) + u_b(x_{B_2}-x_{B_1})(y_{A_2}-y_{A_1}) = u_b(y_{B_2}-y_{B_1})(x_{A_2}-x_{A_1}) & | & move\ u_b\ term\ to\ the\ right \\
(y_{A_1}-y_{B_1})(x_{A_2}-x_{A_1})+ (x_{B_1} -x_{A_1})(y_{A_2}-y_{A_1}) = u_b(y_{B_2}-y_{B_1})(x_{A_2}-x_{A_1}) - u_b(x_{B_2}-x_{B_1})(y_{A_2}-y_{A_1}) & | & extract\ u_b\ on\ the\ right \\
(y_{A_1}-y_{B_1})(x_{A_2}-x_{A_1})+ (x_{B_1} -x_{A_1})(y_{A_2}-y_{A_1}) = u_b((y_{B_2}-y_{B_1})(x_{A_2}-x_{A_1}) - (x_{B_2}-x_{B_1})(y_{A_2}-y_{A_1})) & | & divide \\
\frac{(x_{A_2}-x_{A_1})(y_{A_1}-y_{B_1})- (y_{A_2}-y_{A_1})(x_{A_1}-x_{B_1})}{(y_{B_2}-y_{B_1})(x_{A_2}-x_{A_1}) - (x_{B_2}-x_{B_1})(y_{A_2}-y_{A_1})} = u_b & | & flip\ one\ term\ pair\ and\ sign\ ,rearrange \\
\end{matrix}

Do the same for ua. Yep, Yuck.

It's basic algebra, but it's tedious even on paper. Nonetheless you should do this at least once for a system with four unknowns, say. Later, if you can identify the problem you apply "shortcuts", i.e. formulas or (mathematical) algorithms (here: Gaussian elimination).

Addressing books: If every little step was printed, such books would be trice as big. But a good author should at least identify the structure/problem and what rule/formula/steps he applied (and skipped).

This topic is closed to new replies.

Advertisement