-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathopt_circlecon.m
26 lines (22 loc) · 1.07 KB
/
opt_circlecon.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
function [c, ceq] = opt_circlecon(x, param)
% this function is used to check there is no overlap between coils
% x: n*3 (z, theta, r)
z = x(:,1);
theta = x(:,2);
rCoil = x(:,3);
theta = mod(theta, 2*pi); % we are un-bounded for theta and need to wrap values between 0 and 2pi
dTheta = abs(bsxfun(@minus, theta, theta')); % find angular difference
dTheta(dTheta > pi) = 2*pi - dTheta(dTheta > pi); % use shorter path
dZ = abs(bsxfun(@minus,z, z'));
sRcoil = bsxfun(@plus,rCoil, rCoil');
if strcmp(param.coilShape, 'square')
D = 2*sRcoil.^2 - (dZ.^2 + (param.cylnR*dTheta).^2); % max(sRcoil - dZ, sRcoil - param.cylnR*dTheta); % Maximum of overlap in vertical and horizontal direction
else % we have circular coils
D = sRcoil.^2 - (dZ.^2 + (param.cylnR*dTheta).^2); % D shows how much two circles overlapped
end
idx = 1==eye(param.coilN);
D(idx) = -inf; % diagonal elements
D(D<0) = 0;
c = sum(D(:))/2; %max(D, [], 2);
ceq = [];
end