-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointcloud.m
83 lines (70 loc) · 2.41 KB
/
pointcloud.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
% Create diffraction mask that reproduces a user-defined point cloud
% Distances are in units of mm
%
% Coordinate system:
% y
% | x
% <-------------- f -------------> | /
% | /
% | | /
% ------| | |/
% laser | LCD -------------/------------- z
% ------| | /|
% | / |
% / |
% / |
% |
%
% Point cloud: a matrix of size [n_points, 4] where the four columns are
% x, y, z, and amplitude, respectively.
% Wavelength
lambda = 532e-6;
% Define point cloud
% Sphere
% rx = 5;
% ry = 5;
% rz = 5;
% theta = 0.1 * pi : 0.2 * pi : 0.9 * pi;
% phi = 0 : 0.2 * pi : 1.8 * pi;
% pc = make_sphere(rx, ry, rz, theta, phi);
% Two linked circles
rx = 10;
ry = 5;
rz = 50;
theta = 0 : 0.05 * pi : 1.95 * pi;
pc = make_linked_circles(rx, ry, rz, theta);
% Count the number of points in point cloud
fprintf('Number of points in point cloud: %i\n', size(pc, 1))
% Display point cloud
figure
hold on
scatter3(pc(:, 1), pc(:, 2), pc(:, 3), pc(:, 4));
xlabel('x');
ylabel('y');
zlabel('z');
savefig('pc.fig');
hold off
% Distance from the mask to the point defined by x = y = z = 0
f = 300;
% Pixel coordinates
mask_x = -10 : 8.5e-3 : 10;
mask_y = -5 : 8.5e-3 : 5;
[mask_X, mask_Y] = meshgrid(mask_x, mask_y);
% Make diffraction mask
mask_cos = zeros(length(mask_y), length(mask_x));
mask_sin = zeros(length(mask_y), length(mask_x));
for k = 1 : length(pc(:, 1)) % Loop over points in point cloud
% Distances between points on mask to the k-th point in point cloud
mask_R = sqrt((mask_X - pc(k, 1)).^2 + (mask_Y - pc(k, 2)).^2 + (f + pc(k, 3))^2);
% Update mask
mask_cos = mask_cos + pc(k, 4) * cos(2 * pi / lambda * mask_R);
mask_sin = mask_sin + pc(k, 4) * sin(2 * pi / lambda * mask_R);
end
% Rescale
mask_cos = rescale(mask_cos); % rescale to [0, 1]
mask_cos = mask_cos.^2; % square to get intensity
mask_sin = rescale(mask_sin); % rescale to [0, 1]
mask_sin = mask_sin.^2; % square to get intensity
% Write to image
imwrite(mask_cos, 'mask_cos.png')
imwrite(mask_sin, 'mask_sin.png')