forked from jaolive/SiStER
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SiStER_locate_markers_in_grid.m
42 lines (30 loc) · 1.13 KB
/
SiStER_locate_markers_in_grid.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
function [quad,icn,jcn] = SiStER_locate_markers_in_grid(xm,ym,x,y,dx,dy)
% [quad,icn,jcn] = SiStER_locate_markers_in_grid(xm,ym,x,y,dx,dy)
% Tells a marker which cell (and which quadrant of that cell) it belongs to.
% icn,jcn are the indexes of the upper-left shear node of the cell
% that a given marker is currently in
% quad is the quadrant of the cell that contains the marker
% (quad = 1 means bottom-right, then numbered clockwise)
%% Determine Location of Markers and Quadrant of Element
M=length(xm);
icn = zeros(1,M);
jcn = icn;
quad = icn; % quadrant 1 = bottom-right, numbered clockwise
[~, Ix] = min(abs(bsxfun(@minus, xm, x')));
[~, Iy] = min(abs(bsxfun(@minus, ym, y')));
jcn(xm>x(Ix)) = Ix(xm>x(Ix));
jcn(xm<=x(Ix)) = Ix(xm<=x(Ix))-1;
icn(ym>y(Iy)) = Iy(ym>y(Iy));
icn(ym<=y(Iy)) = Iy(ym<=y(Iy))-1;
jcn(jcn==0) = 1;
jcn(jcn>length(dx)) = length(dx);
icn(icn==0) = 1;
icn(icn>length(dy)) = length(dy);
disx = abs((xm-x(jcn))./dx(jcn));
disy = abs((ym-y(icn))./dy(icn));
xRIGHT = disx > 0.5;
yUP = disy > 0.5;
quad(xRIGHT & yUP) = 3;
quad(xRIGHT & ~yUP) = 2;
quad(~xRIGHT & yUP) = 4;
quad(~xRIGHT & ~yUP) = 1;