
function mSurface = plotNormal2d(dimensions, dim1, dim2, weight, mean2d, variance2d, compvariances, resolution, color, zero, ratio) 

    deltaX1 = sqrt(-2.0*variance2d(1,1)*(log(zero)+0.5*log((2*pi)^dimensions*prod(compvariances))));
    deltaX2 = sqrt(-2.0*variance2d(2,2)*(log(zero)+0.5*log((2*pi)^dimensions*prod(compvariances)))); 
    
    t1 = 2*deltaX1 / resolution;
    t2 = 2*deltaX2 / resolution;   
  
    x1 = mean2d(1)-deltaX1 : t1 : mean2d(1)+deltaX1;
    x2 = mean2d(2)-deltaX2 : t2 : mean2d(2)+deltaX2;
    
    z = normal2d(x1, x2, dimensions, mean2d, variance2d, compvariances) * weight;
    if(ratio)
        z = log(z);
    end
    mSurface = mesh(z, 'XData', x1, 'YData', x2, 'EdgeColor', color, 'FaceLighting', 'none'); 
    alpha(0.6); % set transparency of the surface
    view(3); grid on; box on; % enclose the axis in a box
    xl = strcat('X dim ', num2str(dim1));
    yl = strcat('Y dim ', num2str(dim2));
    xlabel(xl);
    ylabel(yl);
    zlabel('Z');
end
    










