The thin lens has some basic properties that have some redundancy but they are the ones I remember and deploy when needed:
- a ray through the lens center is not bent
- all rays through a point that then pass through the lens converge at some other point
- a ray through the focal point (a point on the optical axis at distance from lens f, the focal length of the lens) will be parallel to the optical axis after being bent by the lens
- all rays from a point a distance A from the lens will converge at a distance B on the other side of the lens and obey the thin lens law: 1/A + 1/B = 1/f
So if I have a (purple) ray with origin a that hits the lens at point m, how does it bend? It bends towards point b no matter what the ray direction is. So the new ray is:
p(t) = m + t (b-m)
So what is point b?
It is in the direction of point c, but extended by some distance. We know the center of the lens c, so we can use the ratios of the segments to extend to that:
b = a + (c-a) (B+A) / A?
So what is (B+A) /A?
We know 1/A + 1/B = 1/f, so B = 1/(1/f-1/A). So the point b is:
b = a + (c-a) (1/(1/f-1/A) + A)/A =
b = a + (c-a) (1/(A/f - 1) + 1) =
b = a + (c-a) (A/(A - f))
OK lets try a couple of trivial cases. What if A = 2f?
b = a + (c-a) (2f/(2f-f)) = b = a + 2(c-a)
That looks right (symmetric case-- A = B there)
So final answer, given a ray with origin a that hits a lens with center c and focal length f at point m, the refracted ray is:
p(t) = m + t( a + (c-a) (A/(A - f)) - m)
There is a catch. What if B < 0? This happens when A < f. Address that case when it comes up :)