The goal is to optimize the shape of lens in such a way, that parallel rays
falling into the lens will focus in one single point. The shape is optimized by
modifying the lens segments' thickness.
The lens pieces' height and position are fixed, similar to the ES genotype. The genotype contains n+1 15-Bit pieces for n+1 thickness values, if n is the number of lens pieces.
// 9 lens pieces: 10 thickness values [[011100111000000] [010010110100110] [100101101000011] [110001011000001] [100100011111101] [111101001010100] [011101011100011] [010001011111001] [010111001100001] [010110010111011]]
For each incoming ray 2 refracted rays and 3 points of intersection are calculated:
1.intersection: incoming ray and left lens-border
1.refracted ray: incoming ray at 1.intersection
2.intersection: 1.refracted ray with right lens-border
2.refratced ray: outgoing ray at 2.intersection
3.intersection: 2.refracted ray with focus-plane
For each incoming ray i, let di be the distance of the 3rd intersection-point
and the focus within the focus-plane. Then the quality of a prism lens is calculated
by summing up the squared distances di^2 for each ray.
Calculating the quality for the prism lens is somewhat like doing ray tracing.
We have to calculate refracted rays and points of intersection.
Given a line (the lens border) and an incoming ray I we calculate the refracted
ray T as follows (Ref.: Glassner, Ray Tracing, p.291ff):
T = -p*I+(p*c1-c2)*N
with
N = normal of lens border
p = refraction proportion r2/r1 (lens/medium)
c1 = -I*N = cos(angle between I and N)
c2 = sqrt(1-p^2(1-c1^2)) = cos(angle between T and -N)