-
Notifications
You must be signed in to change notification settings - Fork 21
/
example8.m
47 lines (36 loc) · 1.4 KB
/
example8.m
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function example8()
%
% test a lens with polynomial aspheric terms
%
% Copyright: Yury Petrov, 2016
%
% create a container for optical elements (Bench class)
bench = Bench;
% add optical elements in the order they are encountered by light rays
% front lens surface
lens1 = AsphericLens( [ 40 0 0 ], 31, 80, 0, [ 0 -1e-05 3e-07 ], { 'air' 'pmma' } );
bench.append( lens1 );
% back lens surface
lens2 = AsphericLens( [ 52.5 0 0 ], 31, -10, -2, [ 0 -2e-05 2e-07 ], { 'pmma' 'air' } ); % aspheric surface
bench.append( lens2 );
% screen
screen = Screen( [ 70 0 0 ], 3, 3, 256, 256 );
bench.append( screen );
% create collimated rays with some slant
nrays = 500;
rays_in = Rays( nrays, 'collimated', [ 0 0 0 ], [ 1 0 0 ], 30, 'hexagonal' );
tic;
fprintf( 'Tracing rays... ' );
rays_through = bench.trace( rays_in ); % repeat to get the min spread rays
% draw bench elements and draw rays as arrows
bench.draw( rays_through ); % display everything, the other draw option is 'lines'
% get the screen image in high resolution
nrays = 10000;
rays_in = Rays( nrays, 'collimated', [ 0 0 0 ], [ 1 0 0 ], 30, 'hexagonal' );
bench.trace( rays_in );
figure( 'Name', 'Image on the screen', 'NumberTitle', 'Off' );
imshow( screen.image, [] );
toc;
draw_lens_engineering( [ 40 52.5 ], [ 31 31 ], [ 80 -10 ], [ 0 -2 ], [ 0 -1e-05 3e-07; 0 -2e-05 2e-07 ]', 'pmma' );
fprintf( 'Engineering drawing saved in draw_lens_engineering.pdf\n' );
end