blob: 81f37c5a4d8b3fd28cb2dcced49d00dcb19b0c5b (
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
|
% --- start of displayed preamble in the book ---
vardef reflectray(expr s,a,p)=
save tI,tn,ia,I,J;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);J=I+dir(tn+ia)*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: reflectray(z0,a,p); endfor;
draw p withcolor red;
endfig;
end;
|