function [w b ad]=linear_affinehull_separator(U1,mu1,U2,mu2)
% This function finds the optimal separating hyperplane that separates the
% affine hulls belonging to '+' and '-' classes. 
% All points on '+' affine hull satisfy w'*x+b>0 and all points on '-' affine
% hull satisfy w'*x+b<0.
%   Inputs
%       U1 - basis vectors for the affine hull of '+' class
%       mu1 - mean of the '+' class samples 
%       U2 - basis vectors for the affine hull of '-' class
%       mu2 - mean of the '-' class samples 
%   Outputs
%       w - normal of the separating hyperplane
%       b - bias of the separating hyperplane
%       ad - Euclidean distance between affine hulls
% 
% Written by Hakan Cevikalp, Eskisehir Osmangazi University, 11/3/2008.
% email: hakan.cevikalp@gmail.com

U=orth([U1 U2]);
clear U1 U2
c1=mu1-U*(U'*mu1);
c2=mu2-U*(U'*mu2);
w=c1-c2;
ad=norm(w);
b=-w'*(mu1+mu2)/2;
