How does sphere hit equation expand to quadratic equation in ray tracing?

202 Views Asked by At

This is probably very basic question but I can't understand how the first function is expanded to the second one?

A, B and C are vectors

$(A + tB - C) \cdot (A + tB - C) = r^2$

This should somehow expand to

$t^2(B \cdot B) + 2t(B \cdot A-C) + (A-C) \cdot (A-C) = r^2$

I managed to get the following by using distributivity of addition wrt scalar product, but can't figure out how to proceed:

$A \cdot A + 2t(A \cdot B) - 2(A \cdot C) + (tB-C) \cdot (tB-C) = r^2$

1

There are 1 best solutions below

0
On BEST ANSWER

Just bring the $A$ and $-C$ terms together and treat them as a single term throughout. This is done because they are both constant terms, without a factor $t$.

$$(A + tB - C) \cdot (A + tB - C) = r^2\\ (tB + (A-C)) \cdot (tB + (A-C)) = r^2\\ tB \cdot tB + tB \cdot (A-C) + (A-C)\cdot tB + (A-C)\cdot(A-C)= r^2\\ tB \cdot tB + tB \cdot (A-C) + tB \cdot (A-C) + (A-C)\cdot(A-C)= r^2\\ t^2(B \cdot B) + 2t(B \cdot (A-C)) + (A-C)\cdot(A-C)= r^2\\ $$

It is basically like expanding $(1+x+2)^2$ by first gathering the constants to get $(x+3)^2$.