function wam = wamquadrangle(deg,Q)

% by Alvise Sommariva and Marco Vianello
% University of Padova
% September 1, 2015 

% produces a polynomial Weakly Admissible Mesh for degree deg 
% in a convex quadrangle, namely
% ||p||_quadrangle leq C(deg)*||p||_WAM with C(deg)=O(log^2(deg))

% INPUT:

% deg = polynomial degree

% Q = 2-columns array of the convex quadrangle vertices


% OUTPUT:

% wam = 2-columns array of mesh points coordinates


% FUNCTION BODY

% Chebyshev-Lobatto grid
j=(0:1:deg);
c=cos(j*pi/deg);

A=Q(1,:);
B=Q(2,:);
C=Q(3,:);
D=Q(4,:);

[u,v]=meshgrid(c);

pts=0.25*((1-u(:)).*(1-v(:))*A+(1+u(:)).*(1-v(:))*B);
pts=pts+0.25*((1+u(:)).*(1+v(:))*C+(1-u(:)).*(1+v(:))*D);

% eliminating possible multiple nodes in degenerate cases 
% (triangle, segment)
dig=12;
wam=singlepts(pts,dig);


end

