-
Notifications
You must be signed in to change notification settings - Fork 1
/
f_lightPlaneCircle.m
49 lines (44 loc) · 1.03 KB
/
f_lightPlaneCircle.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
%% Lightsource, Plane light, circular aperture
% coded at 2022-09-14
% by Jungkwuen An ([email protected])
%
% c: center position of plane light
% d: direction vector
% r: radius of circular plane
% n: number of rays in a radial segment (integer)
%
function rays = f_lightPlaneCircle(c, d, r, n)
% trim parameters
c = c(:);
d = d(:);
d = d./norm(d);
n = round(n);
% create initial positions along z-axis
[x,y] = f_polarUniform(r,n);
z = zeros(size(x));
xyz = [x,y,z];
% tilting matrix to the direction vector
% xt, yt, zt are axis vectors for tilted coordiates
T = eye(3);
z0 = [0;0;1];
zt = d;
xt = cross(zt,z0);
if norm(xt) > 0, % unless d is not parallel to z
xt = xt./norm(xt);
yt = cross(zt, xt);
T = [xt,yt,zt];
else
if dot(z0,zt) < 0,
T(end) = -1;
end
end
xyz = xyz*T'; % tilting the initial position
% create rays based on above
rays = {};
for i=1:length(x),
nray = c_Rays();
nray.init = xyz(i,:)'+c;
nray.dir = d;
rays{end+1} = nray;
end
end