-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraytraceSystem3D.m
More file actions
65 lines (51 loc) · 2.07 KB
/
Copy pathraytraceSystem3D.m
File metadata and controls
65 lines (51 loc) · 2.07 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
function [raysOut3D] = raytraceSystem3D(raysIn3D,surfaces,...
refractiveIndices, distances)
%RAYTRACESYSTEM3D this function will raytrace input rays through a system.
%The input must must be a cell array of Ray3D objects.
%The function will output an cell matrix of Ray3D objects.
%
% [raysOut3D] = raytraceSystem3D(raysIn3D,surfaces,...
% refractiveIndices, distances)
% raysIn3D must be a column vector with type RaysIn3D
if ~iscolumn(raysIn3D)
error('raytraceSystem3D:InputDataSize',...
'Ray input is not a column vector!');
end
for iRay = 1:1:size(raysIn3D,1)
if ~isa(raysIn3D{iRay,1},'Ray3D')
error('raytraceSystem3D:InputDatatype',...
'Rays are not type of Ray3D!');
end
end
% system must be row vector with type Surface3D
if ~isrow(surfaces)
error('raytraceSystem3D:InputDataSize',...
'Ray input is not a row vector!');
end
for iRay = 1:1:size(surfaces,2)
if ~isa(surfaces,'Surface3D')
error('raytraceSystem3D:InputDatatype',...
'Rays are not type of Surface3D!');
end
end
% create raysOut cell matrix
raysOut3D = cell(size(raysIn3D,1),size(surfaces,2));
raysOut3D(:,1) = raysIn3D;
% call raytraceSurface3D for each surface
for iSurface = 1:1:size(surfaces,2)
if iSurface == size(surfaces,2)
% take the same n's when reached the image plane
n1 = refractiveIndices(1,size(surfaces,2));
n2 = refractiveIndices(1,size(surfaces,2));
else
% take the n's that we need
n1 = refractiveIndices(1,iSurface);
n2 = refractiveIndices(1,iSurface+1);
end
% raytrace rays as columns vector through the system.
% return the outgoing & modified incoming rays
[raysOut3D(:,iSurface), raysOut3D(:,iSurface+1)] =...
raytraceSurface3D(raysOut3D(:,iSurface),...
surfaces(1,iSurface),n1,n2, distances(1,iSurface));
end
end