summaryrefslogtreecommitdiff
path: root/info/examples/lgc2/4-5-12.mp
blob: 4b0f2bd6026240df4f2dfa25e8b4634d055099dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
% --- start of displayed preamble in the book ---
vardef refractray(expr s,a,p,na,nb)=
  save tI,tn,ia,ib,I,J,sib;pair I,J;
  tI=xpart(p intersectiontimes (s--(s+30cm*dir(a))));
  if tI>=0:
    I=point tI of p;draw s--I;tn=angle(direction tI of p)+90;
    %drawarrow I--(I+dir(tn)*3cm); % normal
    %drawarrow I--(I+dir(180+tn)*3cm);
    ia=tn-angle(s-I);
    % we have na*sind(ia)=nb*sind(ib)
    sib=na*sind(ia)/nb;ib=-angle(1+-+sib,sib);
    J=I+dir(tn+180+ib)*2cm;draw I--J withcolor blue;
  fi;
enddef;
% --- end of displayed preamble in the book ---
defaultfont:="ptmr8r";
warningcheck:=0;
beginfig(1)
numeric u;u=3mm;path p;
p=((5u,-6u)..(4u,-2u)..(4.5u,0)..(5u,5u)) rotated 90;
z0=origin;
for a=-40 step 5 until 140:refractray(z0,a,p,1,1.5);endfor;
draw p withcolor red;
endfig;
end;