function l=drawChapeau(x0,y0,x1,y1)
% DRAWCHAPEAU draws a shape of "Mexican hat," 
% between (x0,y0) and (x1,y1) in 2-dimensional plane.
% Usage : drawChapeau(x0,y0,x1,y1)

% Copyright(C) 2002 Tohru Ikeguchi, All Rights Reserved

% Default value setting
if nargin<1,x0=0;end
if nargin<2,y0=0;end
if nargin<3,x1=1;end
if nargin<4,y1=0;end

% The basic length is L
L=sqrt((x0-x1)^2+(y0-y1)^2);

% A is the information of the Mexican hat.
A=[0 L/3 L/2 L*2/3 L; 0 0 L*sqrt(3)/6 0 0];

[n,m]=size(A);
T = [x0*ones(1,m); y0*ones(1,m)];

% theta is an angle 
theta=acos(dot([1 0],[x1-x0 y1-y0])/norm([x1-x0 y1-y0]));
if y1<y0,theta=-theta;end

if theta ~=0
    R = rotation(theta);
    A = R*A;
end

% Translation
A=A+T;

l=plot(A(1,:),A(2,:),'LineWidth',2);
