| 1 |
% lgc2refractionEdited.mp |
| 2 |
% lgc means LaTeX Graphics Companion |
| 3 |
% 2014 |
| 4 |
|
| 5 |
prologues := 1; |
| 6 |
|
| 7 |
vardef refractray(expr s,a,p,rir)= |
| 8 |
save tI,tn,ia,ib,I,J,sib; |
| 9 |
pair I,J; |
| 10 |
tI = xpart(p intersectiontimes (s--(s+30cm*dir(a)))); |
| 11 |
if tI>=0: |
| 12 |
I=point tI of p; |
| 13 |
draw s--I; |
| 14 |
tn=angle(direction tI of p)+90; |
| 15 |
ia=tn-angle(s-I); |
| 16 |
sib=sind(ia)/rir; |
| 17 |
ib=-angle(1+-+sib,sib); |
| 18 |
J=I+dir(tn+180+ib)*2cm; |
| 19 |
draw I--J withcolor blue; |
| 20 |
fi; |
| 21 |
enddef; |
| 22 |
|
| 23 |
beginfig(1); |
| 24 |
numeric u; |
| 25 |
u=3mm; |
| 26 |
path p; |
| 27 |
p=((5u,-6u)..(4u,-2u)..(4.5u,0)..(5u,5u)) rotated 90; |
| 28 |
for a=40 step 5 until 140: refractray(origin,a,p,1.5); endfor; |
| 29 |
draw p withcolor red; |
| 30 |
endfig; |
| 31 |
|
| 32 |
vardef lensrefractray(expr s,a,p,q,rir)= |
| 33 |
save tI,tn,ia,ib,I,J,K,sib; |
| 34 |
pair I,J,K; |
| 35 |
tI = xpart(p intersectiontimes (s--(s+30cm*dir(a)))); |
| 36 |
if tI>=0: |
| 37 |
I=point tI of p; |
| 38 |
draw s--I; |
| 39 |
tn=angle(direction tI of p)+90; |
| 40 |
ia=tn-angle(s-I); |
| 41 |
sib=sind(ia)/rir; |
| 42 |
ib=-angle(1+-+sib,sib); |
| 43 |
J=I+dir(tn+180+ib)*2cm; |
| 44 |
tI := xpart(q intersectiontimes (I--J)); |
| 45 |
if tI>=0: |
| 46 |
K:=point tI of q; |
| 47 |
draw I--K withcolor blue; |
| 48 |
tn:=angle(direction tI of q)+90; |
| 49 |
ia:=tn-angle(I-K); |
| 50 |
sib:=rir*sind(ia); |
| 51 |
ib:=angle(1+-+sib,sib); |
| 52 |
J:=K+dir(tn+ib)*2cm; |
| 53 |
draw K--J; |
| 54 |
fi; |
| 55 |
fi; |
| 56 |
enddef; |
| 57 |
|
| 58 |
beginfig(2); |
| 59 |
path q; |
| 60 |
q = reverse (p yscaled (-1)) shifted (up*10.5u); |
| 61 |
fill (p--q--cycle) withcolor red; |
| 62 |
for a=46 step 3 until 120: |
| 63 |
lensrefractray(origin,a,p,q,1.4); |
| 64 |
endfor; |
| 65 |
endfig; |
| 66 |
|
| 67 |
vardef reflectray(expr s,a,p,l)= |
| 68 |
save tI,tn,ia,I,J; |
| 69 |
pair I,J; |
| 70 |
tI=xpart(p intersectiontimes (s--(s+30cm*dir(a)))); |
| 71 |
if tI>=0: |
| 72 |
I=point tI of p; |
| 73 |
draw s--I; |
| 74 |
tn=angle(direction tI of p)+90; |
| 75 |
ia=tn-angle(s-I); |
| 76 |
J=I+dir(tn+ia)*l; |
| 77 |
draw I--J withcolor blue; |
| 78 |
fi; |
| 79 |
enddef; |
| 80 |
|
| 81 |
beginfig(3); |
| 82 |
for a=40 step 5 until 140: reflectray(origin,a,p,2cm); endfor; |
| 83 |
draw p withcolor red; |
| 84 |
endfig; |
| 85 |
|
| 86 |
vardef doublereflection(expr s,a,p,q,l,m)= |
| 87 |
save tI,tn,ia,I,J,K; |
| 88 |
pair I,J,K; |
| 89 |
tI=xpart(p intersectiontimes (s--(s+30cm*dir(a)))); |
| 90 |
if tI>=0: |
| 91 |
I=point tI of p; |
| 92 |
draw s--I; |
| 93 |
tn=angle(direction tI of p)+90; |
| 94 |
ia=tn-angle(s-I); |
| 95 |
J=I+dir(tn+ia)*l; |
| 96 |
tI := xpart(q intersectiontimes (I--J)); |
| 97 |
if tI>=0: |
| 98 |
K:=point tI of q; |
| 99 |
draw I--K withcolor blue; |
| 100 |
tn:=angle(direction tI of q)+90; |
| 101 |
ia:=tn-angle(I-K); |
| 102 |
J:=K+dir(tn+ia)*m; |
| 103 |
draw K--J; |
| 104 |
fi; |
| 105 |
fi; |
| 106 |
enddef; |
| 107 |
|
| 108 |
beginfig(4); |
| 109 |
numeric u, ad, len; |
| 110 |
u=3mm; |
| 111 |
ad=83; |
| 112 |
len = 5cm; |
| 113 |
path p,q; |
| 114 |
pair sourc; |
| 115 |
sourc = (-2u,0); |
| 116 |
p=(-5u,0){up}..{right}(3u,9u); |
| 117 |
q=(6u,0)..{dir(ad)}(10u,11u); |
| 118 |
for a=60 step 3 until 120: |
| 119 |
%reflectray(sourc,a,p,len); |
| 120 |
doublereflection(sourc,a,p,q,len,0.3*len); |
| 121 |
endfor; |
| 122 |
draw p withcolor red; |
| 123 |
draw q withcolor red; |
| 124 |
endfig; |
| 125 |
|
| 126 |
end. |