| 1 |
% simplelens.mp |
| 2 |
% L. Nobre G. |
| 3 |
% 2013 |
| 4 |
|
| 5 |
prologues := 1; |
| 6 |
|
| 7 |
numeric specialdist, otherdist; |
| 8 |
specialdist = 2.5cm; |
| 9 |
color TableC[]; |
| 10 |
TableC0 := (0.65,0.61,0.49); % grey %% G N U P L O T |
| 11 |
TableC1 := 0.77red; % red %% |
| 12 |
TableC2 := ( 0.2, 0.2, 1.0 ); % blue %% colors |
| 13 |
TableC3 := ( 1.0, 0.7, 0.0 ); % orange %% |
| 14 |
TableC4 := 0.85green; % pale green %% |
| 15 |
TableC5 := 0.90*(red+blue); % magenta %% |
| 16 |
TableC6 := 0.85*(green+blue); % cyan %% |
| 17 |
TableC7 := 0.85*(red+green); % yellow %% |
| 18 |
|
| 19 |
vardef lensrefractray(expr s,a,p,q,rir,c)= |
| 20 |
save tI,tn,ia,ib,I,J,K,sib; |
| 21 |
pair I,J,K; |
| 22 |
draw s--(s-2cm*dir(a)) withcolor TableC[c]; |
| 23 |
tI = xpart(p intersectiontimes (s--(s+15cm*dir(a)))); |
| 24 |
if tI>=0: |
| 25 |
I=point tI of p; |
| 26 |
draw s--I withcolor TableC[c]; |
| 27 |
tn=angle(direction tI of p)+90; |
| 28 |
ia=tn-angle(s-I); |
| 29 |
sib=sind(ia)/rir; |
| 30 |
ib=-angle(1+-+sib,sib); |
| 31 |
J=I+dir(tn+180+ib)*2cm; |
| 32 |
tI := xpart(q intersectiontimes (I--J)); |
| 33 |
if tI>=0: |
| 34 |
K:=point tI of q; |
| 35 |
draw I--K withcolor TableC0; |
| 36 |
tn:=angle(direction tI of q)+90; |
| 37 |
ia:=tn-angle(I-K); |
| 38 |
if sind(ia)<1/rir: |
| 39 |
sib:=rir*sind(ia); |
| 40 |
ib:=angle(1+-+sib,sib); |
| 41 |
J:=K-dir(tn-ib)*specialdist; |
| 42 |
draw K--J withcolor TableC[c]; |
| 43 |
fi; |
| 44 |
fi; |
| 45 |
fi; |
| 46 |
enddef; |
| 47 |
|
| 48 |
beginfig(1); |
| 49 |
numeric rir, ray, wid, dist, ha, dx, dy, bord, cx, cy, cent, a, sa, nr, m; |
| 50 |
numeric refang, colorcounter; |
| 51 |
path vseg, cseg, lens, cell; |
| 52 |
pen fordot; |
| 53 |
color lenscolor, cellcolor; |
| 54 |
refang = 41; |
| 55 |
m = 1.2mm; |
| 56 |
nr = 9; |
| 57 |
rir = 1.2; |
| 58 |
ray = 2.3cm; |
| 59 |
wid = 3.9cm; |
| 60 |
dist = 1.1cm; |
| 61 |
bord = 1mm; |
| 62 |
fordot = pencircle scaled 1mm; |
| 63 |
lenscolor = 0.6white; |
| 64 |
cellcolor = 0.4white; |
| 65 |
dy = 0.5*wid; |
| 66 |
dx = ray+-+dy; |
| 67 |
cx = 0.5*bord; |
| 68 |
cy = dy-bord; |
| 69 |
cent = dx-dist; |
| 70 |
ha = angle(dist,cy); |
| 71 |
sa = 2ha/nr; |
| 72 |
z1 = (dx,ray); |
| 73 |
z2 = (dx,-ray); |
| 74 |
z3 = (cent,0); |
| 75 |
z4 = (dx,cy); |
| 76 |
z5 = (dx,-cy); |
| 77 |
z6 = (0,cy); |
| 78 |
z7 = (0,-cy); |
| 79 |
z8 = (ray,cy); |
| 80 |
z9 = (ray,-cy); |
| 81 |
vseg = z2--z1; |
| 82 |
%cseg = halfcircle rotated -90 scaled 2ray; |
| 83 |
cseg = (dx,-dy){dir(refang)}..(ray,0)..{dir(180-refang)}(dx,dy); |
| 84 |
lens = buildcycle(reverse vseg,z7--z9,cseg,z8--z6); |
| 85 |
fill lens withcolor lenscolor; |
| 86 |
cell = ((cx,cy)--(-cx,cy)--(-cx,-cy)--(cx,-cy)--cycle) shifted z3; |
| 87 |
fill cell withcolor cellcolor; |
| 88 |
%draw z3 withpen fordot; |
| 89 |
colorcounter = 1; |
| 90 |
for a=0.5*sa step sa until ha-sa: |
| 91 |
if not (colorcounter<>7): |
| 92 |
colorcounter:= 1; |
| 93 |
else: |
| 94 |
colorcounter := incr(colorcounter); |
| 95 |
fi; |
| 96 |
lensrefractray(z3,a,vseg,cseg,1.9,colorcounter); |
| 97 |
lensrefractray(z3+up*m,a,vseg,cseg,1.9,colorcounter); |
| 98 |
lensrefractray(z3+down*m,a,vseg,cseg,1.9,colorcounter); |
| 99 |
if not (colorcounter<>7): |
| 100 |
colorcounter:= 0; |
| 101 |
else: |
| 102 |
colorcounter := incr(colorcounter); |
| 103 |
fi; |
| 104 |
lensrefractray(z3,-a,vseg,cseg,1.9,colorcounter); |
| 105 |
lensrefractray(z3+up*m,-a,vseg,cseg,1.9,colorcounter); |
| 106 |
lensrefractray(z3+down*m,-a,vseg,cseg,1.9,colorcounter); |
| 107 |
endfor; |
| 108 |
otherdist = ray+specialdist-0.5cm; |
| 109 |
clip currentpicture to (-otherdist,-cy)--(-otherdist,cy)--(otherdist,cy)--(otherdist,-cy)--cycle; |
| 110 |
endfig; |
| 111 |
|
| 112 |
end. |
| 113 |
|
| 114 |
|