1 ## Copyright (c) 2012 Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 3 of the License, or
6 ## (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
17 %% @deftypefn {Function File} {@var{K} = } ellipse2cov (@var{elli})
18 %% @deftypefnx {Function File} {@var{K} = } ellipse2cov (@var{ra}, @var{rb})
19 %% @deftypefnx {Function File} {@var{K} = } ellipse2cov (@dots{}, @var{theta})
20 %% Calculates covariance matrix from ellipse.
22 %% If only one input is given, @var{elli} must define an ellipse as described in
23 %% @command{ellipses2d}.
24 %% If two inputs are given, @var{ra} and @var{rb} define the half-lenght of the
26 %% If a third input is given, @var{theta} must be the angle of rotation of the
27 %% ellipse in radians, and in counter-clockwise direction.
29 %% The output @var{K} contains the covariance matrix define by the ellipse.
31 %% Run @code{demo ellipse2cov} to see an example.
33 %% @seealso{ellipses2d, cov2ellipse, drawEllipse}
36 function K = ellipse2cov (elli, varargin);
41 switch numel (varargin)
49 theta = elli(1,5)*pi/180;
72 T = createRotation (theta)(1:2,1:2);
73 K = T*diag([ra rb])*T';
78 %! elli = [0 0 1 3 -45];
80 %! % Create 2D normal random variables with covarinace defined by elli.
81 %! K = ellipse2cov (elli)
82 %! L = chol(K,'lower');
83 %! u = randn(1e3,2)*L';
88 %! plot(u(:,1),u(:,2),'.r');
90 %! drawEllipse(elli,'linewidth',2);