-
Notifications
You must be signed in to change notification settings - Fork 1
/
rectangleCorners.m
43 lines (37 loc) · 1.02 KB
/
rectangleCorners.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
%% RECTANGLECORNERS Returns patch x and y coordinates for a rectangle with corner at (x,y) and with the given width/height
function [cornerX, cornerY] = rectangleCorners(x, y, width, height, doClose)
if nargin < 5
doClose = false;
end
if isempty(width)
width = 0;
end
if isempty(height)
height = 0;
end
% Canonical format of arguments
x = x(:)';
y = y(:)';
width = width(:)';
height = height(:)';
% Equalize sizes
if numel(x) == 1 && numel(y) > 1
x = x * ones(size(y));
elseif numel(y) == 1 && numel(x) > 1
y = y * ones(size(x));
end
cornerX = [ x ...
; x + width ...
; x + width ...
; x ...
];
cornerY = [ y + height ...
; y + height ...
; y ...
; y ...
];
if doClose
cornerX(end+1,:) = cornerX(1,:);
cornerY(end+1,:) = cornerY(1,:);
end
end