clc; clear all ;
% Define the vertices of the triangle
v1 = [0, 0];
v2 = [20, 0];
v3 = [30, -10];
v4 = [50, -10];
v5 = [50, -20];
v6 = [0, -20];
% Create a matrix with the vertices as rows
vertices = [v1; v2; v3; v4; v5; v6; v1];
% % Define the faces of the triangle as a 1-by-3 matrix
% faces = [1, 2, 3, 4, 5, 6];
%
% % Create a patch object with the specified vertices and faces
% patch('Vertices', vertices, 'Faces', faces, 'FaceColor', 'white');
%
% % Set the axis limits and labels
% axis([0, 50, -20, 0]);
% xlabel('x-axis');
% ylabel('y-axis');
%
% hold on
x1=0;
x2=50;
y1=0;
y2=-20;
npoints_x=51;
npoints_y=21;
% Create a grid of points using the meshgrid function
x_grid = linspace(x1, x2, npoints_x);
y_grid = linspace(y1, y2, npoints_y);
[X, Y] = meshgrid(x_grid, y_grid);
Z = rand(size(X)) ;
idx = inpolygon(X,Y,vertices(:,1),vertices(:,2)) ;
Z(~idx) = NaN ;
h = pcolor(X,Y,Z) ;
h.EdgeColor = 'none' ;