2
$\begingroup$

So i am working through the book "Raytracing in one weekend". At the point where i am at we want to check if a ray hits a sphere. For that we have the equation:

dot((A + t*B - C),(A + t*B - C)) = R*R

Where A + t*B is a point on the ray, with A the start, B the direction and t how far along we went on the ray.

To solve this the author transformed the equation to:

t*t*dot(B,B) + 2*t*dot(A-C,A-C) + dot(C,C) - R*R = 0

Now i just can not understand how this transformation comes about. Simply multiplying this out seems to give a way different result.

Is there some kind of vector math i'm missing here?

$\endgroup$
1

1 Answer 1

3
$\begingroup$

I think there might be a misprinting in the book. I am getting this

$((A-C) + tB)\cdot((A-C) + tB) = R\cdot R$

Let A-C = Y

$(Y + tB)\cdot(Y + tB) = R\cdot R$

$Y\cdot Y + Y\cdot tB + tB\cdot Y + t^2B\cdot B = R\cdot R$

Substituting back

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

$\endgroup$
1
  • $\begingroup$ Yeah i looked at the later code now after giving up and it was definitly a missprint. It works out with (A-C) = y as you said. $\endgroup$
    – Siniyas
    Commented Oct 29, 2017 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.