how to plot 3d inequalities on matlab

前端 未结 3 1723
情书的邮戳
情书的邮戳 2020-12-19 18:19

I want to plot a 3d region in MATLAB bounded from a set of inequalities.

For example:

0 <= x <= 1

sqrt(x) <= y <= 1

0 <= z <= 1          


        
3条回答
  •  感动是毒
    2020-12-19 18:59

    You can do almost the same thing as in the 2d case that you linked to. Just write down your three inequalities, use a 3d meshgrid, multiply each inequality with a number from a set of three numbers that has unique subset sums (e.g. 2, 4, 8) and use scatter3:

    [X,Y,Z]=meshgrid(0:0.1:1,0:0.1:1,0:0.1:1); % Make a grid of points between 0 and 1
    p1=0.1; p2=0.2; % Choose some parameters
    ineq1 = (X >= 0 & X <= 1) * 2;
    ineq2 = (X >= sqrt(X) & Y <= 1) * 4;
    ineq3 = (Z >= 0 & Z <= 1 - Y) * 8;
    colors = zeros(size(X))+ineq1+ineq2+ineq3;
    scatter3(X(:),Y(:),Z(:),3,colors(:),'filled')
    

提交回复
热议问题