# comp.graphics.algorithms

## Subject: Re: line intersecting point in 3d

Hans-Bernhard Broeker wrote:
> jaso wrote:
>> Hi,
>> I've read about the basics of vectors, but I still don't know
>> how to find out if a line intersects a point in 3d space.
>
> Lines don't really "intersect" points. They go through them. But
> this will so rarely be the case for random inputs that you can
> probably get away with always answering "no" without even looking at
> the input. The few cases where it should have said "yes" are unlikely
> to be noticed.
>
>> If I have a ray starting at origin O, and travelling
>> with vector V, how do I know if it hits point P?
>
>> That is:
>
>> Ray = O + Vt
>
> Not quite. The ray is the set of all points formed by O + V*t.
>
>> Point = P
>
> So you want to know whether P is in that set. So see if you
> can form P like that:
>
> P = O + V*t
>
> Elementary algebray transforms that to
>
> (P - O) = V*t
>
> Those are 3 equations (since these are 3-vectors) for a single unknown
> (t). Which, if you paid attention in algebra class, will tell you
> that odds are this equation will not hold: the system of equations is
> over-determined. So you'll have to add some tolerance, making one or
> both objects thicker so they get a non-negligeable chance of hitting
> each other. I.e. you'll have to change the question to be about the
> intersection between a line and a sphere, or a cylinder and a point.
>

Thanks for the help!

Ok, I'm now trying to calculate intersections against a sphere.

According to
http://astronomy.swin.edu.au/~pbourke/geometry/sphereline/
the expression b * b - 4 * a * c will be less than 0 if
the line is not intersecting. So now I'm just trying to draw a
circle by drawing a color if it is inside the circle.
It seems to work, but I can't get the coordinates right,
either the circle is too small or too large, filling up the whole
screen.

So can anyone help me give me good values for my scene, like the
coordinates for my camera, x & y is 0, and z should be negative.
Viewport resolution is 320x200, and the sphere should be at the
center, that is x, y is 0, and z positive.

Thanks!