Lichtstrahlen, die durch eine Linse gebrochen werden
Author: Peter Scholl

M_2 = (3, 2)
r1 = 3
M_1 = (9, 2)
B = Point(yAxis)
n = 141 (slider from 1 to 1000, step 1)
d = CircleArc(M_1, (6, 2 + r1), (6, 2 - r1))
Liste1 = Sequence(Ray[B, B + (sin(180 * ° / (n + 1) * i), -cos(180 * ° / (n + 1) * i))], i, 1, n)
Liste2 = RemoveUndefined(Sequence[Intersect[d, Element[Liste1, i]], i, 1, n])
ni = 1.5 (slider from 0.2 to 1.8, step 0.01)
e = CircleArc(M_2, (6, 2 - r1), (6, 2 + r1))
Liste5 = Sequence(gebrStrahl[B, Element[Liste2, i], Vector[M_1 - Element[Liste2, i]], ni], i, 1, Length[Liste2])
Liste6 = Sequence(Intersect[e, Element[Liste5, i]], i, 1, Length[Liste5])
Liste3 = Sequence(Segment[Element[Liste2, i], B], i, 1, Length[Liste2])
Liste8 = Sequence(Segment[Element[Liste2, i], Element[Liste6, i]], i, 1, Length[Liste2])
l5 = Length(Liste5)
Liste4 = Sequence(Ray[M_1, Element[Liste2, i]], i, 1, Length[Liste2])
Liste7 = Sequence(gebrStrahl[Element[Liste2, i], Element[Liste6, i], Vector[M_2 - Element[Liste6, i]], ni], i, 1, Length[Liste2])

Tool: gebrStrahl
Startpunkt;Auftreffpunkt,Lotrichtung dichtes Medium,Brechindex
Input: A, B, u, n
Output: b

uu: u / Length[u]
v = Vector(A, B)
vu: v / Length[v]
cosα: abs(uu * vu)
sinα: sqrt(1 - cosα^(2))
sinβ: sinα / n^(sgn(uu * vu))
cosβ: sqrt(1 - sinβ^(2))
faka: sinβ / (cosβ * sqrt((1 + cosα) / 2) + sinβ * sqrt((1 - cosα) / 2))
fakb: (sinα * cosβ - cosα * sinβ) / (cosβ * sqrt((1 + cosα) / 2) + sinβ * sqrt((1 - cosα) / 2))
l: fakb * sgn(uu * vu) * uu + faka * vu
b = Ray(B, l)