-
Notifications
You must be signed in to change notification settings - Fork 31
/
example_sphere.m
126 lines (92 loc) · 3.23 KB
/
example_sphere.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
% Example calculation of forces on a sphere in a optical beam
%
% This example includes a couple of example beams (Gaussian, LG and HG),
% combining the separate example scripts found in ottv1.
%
% This file is part of the optical tweezers toolbox.
% See LICENSE.md for information about using/distributing this file.
% Add the toolbox to the path (assuming we are in ott/examples)
addpath('../');
% Close open figures
close all;
%% Describe the particle, beam and surrounding medium
% Make warnings less obtrusive
ott.warning('once');
ott.change_warnings('off');
% Refractive index of particle and medium
n_medium = 1.33;
n_particle = 1.59;
% Wavelength of light in vacuum [m]
wavelength0 = 1064e-9;
% Calculate the wavelength in the medium
wavelength_medium = wavelength0/n_medium;
% Radius of particle
radius = 1.0*wavelength_medium;
% Set the beam type (must be one of lg, gaussian or hg)
% This is used bellow to select from the beam presets
beam_type = 'gaussian';
% Specify the numerical aparture of the beam/microscope
NA = 1.02;
%% Setup the T-matrix for the particle
tic
% Create a T-matrix for a sphere
T = ott.Tmatrix.simple('sphere', radius, 'wavelength0', wavelength0, ...
'index_medium', n_medium, 'index_particle', n_particle);
disp(['T-matrix calculation took ' num2str(toc) ' seconds']);
%% Calculate the beam shape coefficients
tic
switch beam_type
case 'gaussian'
% Create a simple Gaussian beam with circular polarisation
% We could also calculate the beam angle ourseves and specify that.
beam = ott.BscPmGauss('NA', NA, 'polarisation', [ 1 1i ], ...
'index_medium', n_medium, 'wavelength0', wavelength0);
case 'lg'
% Create a LG03 beam with circular polarisation
beam = ott.BscPmGauss('lg', [ 0 3 ], ...
'polarisation', [ 1 1i ], 'NA', NA, ...
'index_medium', n_medium, 'wavelength0', wavelength0);
case 'hg'
% Create a HG23 beam with circular polarisation
beam = ott.BscPmGauss('hg', [ 2 3 ], ...
'polarisation', [ 1 1i ], 'NA', NA, ...
'index_medium', n_medium, 'wavelength0', wavelength0);
otherwise
error('Unsupported beam type');
end
% Normalize the beam power
beam.power = 1.0;
disp(['Beam calculation took ' num2str(toc) ' seconds']);
%% Generate force/position graphs
tic
% Calculate the force along z
z = [0;0;1]*linspace(-8,8,80)*wavelength_medium;
fz = ott.forcetorque(beam, T, 'position', z);
% Find the equilibrium along the z axis
zeq = ott.find_equilibrium(z(3, :), fz(3, :));
if isempty(zeq)
warning('No axial equilibrium in range!')
zeq=0;
end
zeq = zeq(1);
% Calculate force along x-axis (with z = zeq, if found)
r = [1;0;0]*linspace(-4,4,80)*wavelength_medium + [0;0;zeq];
fr = ott.forcetorque(beam, T, 'position', r);
disp(['Force calculation took ' num2str(toc) ' seconds']);
%% Generate the plots
figure(1); plot(z(3, :)/wavelength_medium,fz(3, :));
xlabel('{\it z} [\lambda_m]');
ylabel('{\it Q_z} [n_m P / c]');
aa = axis;
hold on;
line(aa(1:2),[ 0 0 ],'linestyle',':');
line([0 0],aa(3:4),'linestyle',':');
hold off;
figure(2); plot(r(1, :)/wavelength_medium,fr(1, :));
xlabel('{\it r} [\lambda_m]');
ylabel('{\it Q_r} [n_m P / c]');
aa = axis;
hold on;
line(aa(1:2),[ 0 0 ],'linestyle',':');
line([0 0],aa(3:4),'linestyle',':');
hold off;