Code covered by the BSD License

• E=c2h(Q,c) E=c2h(Q,c); Transforms a quadratic surface from center to homogeneous form.
• [Q,c]=h2c(E) [Q,c]=h2c(E); Transforms a quadratic surface from homogeneous to center form.
• View all files

### Giampiero Campa (view profile)

10 Nov 2009 (Updated )

Convert quadratics from Homogeneous to Center form and back.

E=c2h(Q,c)
```function E=c2h(Q,c)

% E=c2h(Q,c); Transforms a quadratic surface from center to homogeneous form.
% Given an nD quadratic hyper-surface in center form (x'-c')*inv(Q)*(x-c)=1,
% which is used, for example, by the ellipsoid toolbox, this functions finds
% E relative to the homogeneous coordinates form [x' 1]*E*[x;1]=0.
% When called with only one argument, e.g. E=c2h(Q) then the center c
% is assumed to be zero. Note that the symmetry of Q is enforced at
% various point while calculating E. Also note that the homogeneous
% representation E is invariant to multiplication by any scalar k.
% example:
% E=c2h(diag([1 4]),[0 0]'); % zero-centered ellipse of semiaxes 1 and 2

% Giampiero Campa, Aug 2009, Copyright by The MathWorks, Inc.

% argument check
if nargin<1,
error('c2h needs at least the input matrix Q: E=c2h(Q,c);');
end

% argument check
if nargin>2,
error('Too many output arguments. Usage: E=c2h(Q,c);');
end

% usual preliminary checks on Q
if isempty(Q) || ~isnumeric(Q) || ~isa(Q,'double') || ~isreal(Q),
error('Q must be a real matrix');
end

% Q must be square
if size(Q,1)~=size(Q,2),
error('Q must be square');
end

n=size(Q,1);

% must be at least 1 by 1
if n<1, error('Q cannot be empty'); end

% argument check on c
if nargin==1,
% disp('Center c assumed to be zero');
c=zeros(n,1);
end

% usual preliminary checks on c
if isempty(c) || ~isnumeric(c) || ~isa(c,'double') || ~isreal(c),
error('c must be a real vector');
end

% c must be n by 1
if size(c,1)~=n || size(c,2)~=1,
error(['c must be a ' num2str(n) ' by 1 vector']);
end

% enforce symmetry
Q=(Q'+Q)/2;

% find matrix F
F=inv(Q);

% enforce symmetry
F=(F'+F)/2;

% find vector h and scalar g
h=-F*c;
g=c'*F*c-1;

% compose homogeneous form
E=[F h; h' g];
```