File: Ellipse.m

package info (click to toggle)
psychtoolbox-3 3.0.14.20170103%2Bgit6-g605ff5c.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 103,044 kB
  • ctags: 69,483
  • sloc: ansic: 167,371; cpp: 11,232; objc: 4,708; sh: 1,875; python: 383; php: 344; makefile: 207; java: 113
file content (44 lines) | stat: -rw-r--r-- 1,372 bytes parent folder | download | duplicates (5)
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
function bool = Ellipse(a,b,horpow,verpow)
% Ellipse(a) creates a Circle with
% diameter == ceil(2*a)
%
% Ellipse(a,b) creates an Ellipse with
% horizontal axis == ceil(2*a) and vertical axis == ceil(2*b)
%   
% Ellipse(a,b,power) generates a superEllipse according to the
% geometric formula (x./a).^power + (y./b).^power < 1
%
% Ellipse(a,b,horpow,verpow) generates a generalized superEllipse according
% to the geometric formula (x./a).^horpow + (y./b).^verpow < 1
%
% For more info on superEllipses, see
%   http://en.wikipedia.org/wiki/SuperEllipse
%
% Ellipse returns a (tighly-fitting) boolean matrix which is true for all
% points on the surface of the Ellipse and false elsewhere

% DN 2008
% DN 2009-02-02 Updated to do Circles and input argument handling more
%               efficiently
% DN 2011-08-31 Output wasn't always of right size (ceil(2*input))
% DN 2016-08-25 Switched from deprecated nargchk to narginchk

narginchk(1,4);

if nargin < 2
    b = a;
end
if nargin < 3
    horpow = 2;
end
if nargin < 4
    verpow = horpow;
end

[x,y]   = meshgrid(linspace(-a,a,ceil(2*a)+2),linspace(-b,b,ceil(2*b)+2));

bool    = abs(x./a).^horpow + abs(y./b).^verpow  < 1;

% return in a tight-fitting matrix
cropcoords  = CropBlackEdges(bool);
bool        = bool(cropcoords(3):cropcoords(4),cropcoords(1):cropcoords(2));