minimum time after which line segment connecting points P and Q does not intersect the sphere

Hello,
This is my first post here.
I am trying to solve a question

You are given two points P and Q and an opaque sphere in a three-dimensional space. The point P is not moving, while Q is moving in a straight line with constant velocity. You are also given a direction vector d with the following meaning: the position of Q at time t is Q(t)=Q(0)+d⋅t, where Q(0) is the initial position of Q.

It is guaranteed that Q is not visible from P initially (at time t=0). It is also guaranteed that P and Q do not touch the sphere at any time.

Find the smallest positive time tv when Q is visible from P, i.e. when the line segment connecting points P and Q does not intersect the sphere.

I am using the following logic in my program but it does not work

For the line to "just touch" the sphere, the minimum distance between the line and the sphere must be exactly r.
Please help.

Do you have an image of what you're trying to explain? This sounds very abstract and hard to understand?
Where are Q and P initially, relative to the sphere?
What does
It is guaranteed that Q is not visible from P initially (at time t=0).
mean?
Where is Q moving towards?
What is d⋅t in Q(t)=Q(0)+d⋅t?
What is your question? Are you trying to check if Q intersects with the sphere?
@vandita,

The logic that you are trying to implement is fine: this is certainly (one) way of doing the problem. (If you actually set out to find that minimum distance then you may see that there are slightly more direct ways of doing it.)

You need to show your code before we can comment further.

This is a codechef problem and is already being discussed on other threads, like this one:
http://www.cplusplus.com/forum/beginner/237932/#msg1062188
You might do well to green-tick this thread as closed and switch to the other thread.
Topic archived. No new replies allowed.