-
Notifications
You must be signed in to change notification settings - Fork 10
/
Ray.m
134 lines (112 loc) · 3.68 KB
/
Ray.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
%% Ray
% Ray trace result container
%
%
%
% properties
% position intersection point at each surface [x1,y1,z1];[x2,y2,z2]...
% direction direction cosine after refract [l,m,n]
%
classdef Ray < handle
properties
pupilX = 0.0;
pupilY = 0.0;
sourcePosition = [0,0,0]; % object
sourceDirection = [0,0,1];
positions = []; % each surface including image plane
directions = [];
normdirections =[];
end
properties(Dependent)
x;
y;
z;
l;
m;
n;
srl;
srm;
srn;
end
methods
function self = Ray(px=0.0, py=0.0, srcP=[0,0,0], srcD=[0,0,1], p=[0,0,0], d=[0,0,1])
if nargin ~= 0
self.pupilX = px;
self.pupilY = py;
self.sourcePosition = srcP; % object
self.sourceDirection = srcD;
self.positions = p; % each surface including image plane
self.directions = d;
end
end
function disp(self)
fprintf('Ray parameters:\n');
fprintf('%2s %12s %12s %12s %12s %12s %12s\n', 'S', 'x', 'y', 'z', 'l', 'm', 'n');
for i = 1:size((self.positions),1)
fprintf('%2d %12f %12f %12f %12f %12f %12f\n', i, self.x(i), self.y(i), self.z(i), self.l(i), self.m(i), self.n(i));
end
end
function self = reserve(self, nsurf)
self.positions = zeros(nsurf,3);
self.directions = zeros(nsurf,3);
self.normdirections = zeros(nsurf,3);
end
function self = insert(self, atsurf, newPos=[0,0,0], newDir=[0,0,1], newNormDir=[0,0,1])
self.positions(atsurf,:) = newPos;
self.directions(atsurf,:) = newDir;
self.normdirections(atsurf,:) = newNormDir;
end
function self = append(self, newPos=[0,0,0], newDir=[0,0,1],newNormDir=[0,0,1])
%fprintf('Call Ray.append\n');
cur = self.positions;
self.positions = vertcat(cur,newPos);
cur = self.directions;
self.directions= vertcat(cur,newDir);
cur = self.normdirections;
self.normdirections= vertcat(cur,newNormDir);
end
function vec = get.x(self)
vec = self.positions(:,1);
end
function vec = get.y(self)
vec = self.positions(:,2);
end
function vec = get.z(self)
vec = self.positions(:,3);
end
function vec = get.l(self)
vec = self.directions(:,1);
end
function vec = get.m(self)
vec = self.directions(:,2);
end
function vec = get.n(self)
vec = self.directions(:,3);
end
function vec = get.srl(self)
vec = self.normdirections(:,1);
end
function vec = get.srm(self)
vec = self.normdirections(:,2);
end
function vec = get.srn(self)
vec = self.normdirections(:,3);
end
function val = aoi(self,n)
if n == 1
dirin = self.sourceDirection;
else
dirin = self.directions(n-1,:);
end
snorm = -self.normdirections(n,:);
cosI = dot(dirin, snorm) / ( norm(dirin)*norm(snorm) );
val = acos(cosI);
end
function val = aor(self, n)
dirout = self.directions(n,:);
snorm = -self.normdirections(n,:);
cosId = dot(dirout, snorm) / ( norm(dirout)*norm(snorm) );
val = acos(cosId);
end
end % methods end
end % classdef end