-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathboundingRectGrid.m
36 lines (31 loc) · 1.03 KB
/
boundingRectGrid.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
%
% Function to build a bounding rectangle (CW polygon) with 2 vectors
% which are used to build a grid. Points on edges are
% required even if edges are straight.
%
% Copyright 2016 Elliot Sefton-Nash
function [x, y] = boundingRectGrid(xv, yv)
nx = numel(xv);
ny = numel(yv);
if nx == 0 || ny == 0;
x = []; y = [];
elseif nx == 1 && ny == 1
x = xv; y = yv;
else
xv = sort(xv, 'ascend');
yv = sort(yv, 'ascend');
if nx == 1 && ny > 1
x = repmat(xv, [1 ny]);
y = yv;
elseif ny == 1 && nx > 1
x = xv;
y = repmat(yv, [1 nx]);
else
xl = [min(xv) max(xv)];
yl = [min(yv) max(yv)];
% LL -> UL -> UR -> LR
x = [repmat(xl(1),[1 ny]) xv(2:end) repmat(xl(2),[1,ny-1]) reverse(xv(2:end-1)) ];
y = [yv repmat(yl(2),[1,nx-1]) reverse(yv(1:end-1)) repmat(yl(1),[1,nx-2]) ];
end
end
end