-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_raytraceSystem3D.m
More file actions
87 lines (61 loc) · 2.4 KB
/
Copy pathtest_raytraceSystem3D.m
File metadata and controls
87 lines (61 loc) · 2.4 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function tests = test_raytraceSystem3D
tests = functiontests(localfunctions);
end
function test_raytraceSystem3D_biConvexLens_singleRay(testCase)
% create single ray
raysIn = Ray3D([2e-3, 1e-3, 2e-3], [0.2,0.2,0], 1);
% create many rays
numberOfRays = 10;
raysInCell = cell(numberOfRays,1);
for iSurface = 1:1:numberOfRays
raysInCell{iSurface,1} = raysIn;
end
% create surfaces
surface1 = Surface3D([0,0,30e-3], 20e-3 ,1.5);
surface2 = Surface3D([0,0,5e-3], -10e-3 ,1.5);
surface3 = Surface3D([0,0,27e-3], inf ,1);
% create system
system = [surface1, surface2, surface3];
distances = [10e-3,5e-3,12e-3];
refractiveIndices = [1.0,1.5,1.0];
rounding = 100;
% expected output1 rays and round
raysOut1 = Ray3D([3.78485e-3, 2.78485e-3, 0.559848e-3],...
[0.064202,0.0824673,0.994524], 1.5);
raysOut2 = Ray3D(round([3.98453e-3, 3.04134e-3, -1.34704e-3],rounding),...
round([-0.135022,-0.052866,0.989431],rounding), 1);
raysOut3 = Ray3D([2.16314e-3, 2.32819e-3, 0],...
[-0.135022,-0.052866,0.989431], 1);
raysOutCell = cell(numberOfRays,3);
for iRay = 1:1:numberOfRays
raysOutCell{1,1} = raysOut1;
raysOutCell{1,2} = raysOut2;
raysOutCell{1,3} = raysOut3;
end
% raytrace through system
tic;
raysOut = raytraceSystem3D(raysInCell, system, refractiveIndices, distances);
toc;
for iRay = 1:1:numberOfRays
verifyRay2(raysOut{iRay,1}, raysInCell{1,1}, 0.001, testCase)
verifyRay2(raysOut{iRay,2}, raysOut1, 0.001, testCase)
verifyRay2(raysOut{iRay,3}, raysOut2, 0.001, testCase)
verifyRay2(raysOut{iRay,4}, raysOut3, 0.001, testCase)
end
end
function verifyRay(rayToTest, origin, direction, n, relTol, testCase)
verifyEqual(testCase, rayToTest.origin,...
origin, 'RelTol',relTol)
verifyEqual(testCase, rayToTest.direction,...
direction, 'RelTol',relTol)
verifyEqual(testCase,rayToTest.n,...
n, 'RelTol',relTol)
end
function verifyRay2(rayToTest, referenceRay, relTol, testCase)
verifyEqual(testCase, rayToTest.origin,...
referenceRay.origin, 'RelTol',relTol)
verifyEqual(testCase, rayToTest.direction,...
referenceRay.direction, 'RelTol',relTol)
verifyEqual(testCase,rayToTest.n,...
referenceRay.n, 'RelTol',relTol)
end