# How to determine this kind of vector?

Take a look at the picture. I've got a camera(brown) and its ray(red). As I know ray has a direction and unlimited length(if you don't set it yourself). But now I need to determine ray's vector that starts at camera point and ends when it crosses a floor. How can I do that?

• there are many rays that cross a floor, which one do you need? – ratchet freak Dec 12 '14 at 9:47

I assume you know the ray direction, otherwise there are infinite rays that cross the floor. It crosses the floor when your camera pos (x,y,z) offset by a scaled ray direction k*(a,b,c) has zero height, so:

y + k*b = 0 => (we only care about the y component)
k = -y/b

so the vector that you need to add to the camera is

(-y/b)*(a,b,c)

Of course, it goes without saying that you need to check for special case when b == 0, where the ray is parallel to the xz plane, so it will never cross it, unless on it (y==0)

• Is there a mistake? Why k was -y/b and then became b/y? – Tony Dec 12 '14 at 11:15
• duh, thanks, my bad, fixed it. it should stay -y/b. – Babis Dec 12 '14 at 11:24

The equation of the ray is p = camerapos + t*ray which is 3 equations (after splitting it up the coordinates):

p.x = camerapos.x + t*ray.x
p.y = camerapos.y + t*ray.y
p.z = camerapos.z + t*ray.z


then we know we want the point with p.y = 0 so lets fill it in:

0 = camerapos.y + t*ray.y
t = -camerapos.y / ray.y


then just fill in the t in the first equation: p = camerapos + (-camerapos.y / ray.y)*ray