I want to build a three-dimensional area in MATLAB, limited by a set of inequalities.
For instance:
0 <= x <= 1 sqrt(x) <= y <= 1 0 <= z <= 1 - y
I found a 2d example that someone made on this site, but I'm not sure how to convert it to 3d. How to build inequality .
Edit: From @Tobold's help, I changed the code to limit the points that are plotted on those that are defined by all three regions, but it only displays 2 or 3 points. It seems that the points in the vectors X1, Y1 and Z1 are right, but for some reason it only lays a few. Any ideas why this is just building a few points from the vectors X1, Y1 and Z1 instead of all of them?
[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 X1 = (X >= 0 & X <= 1) & (Y >= sqrt(X) & Y <= 1) & (Z >= 0 & Z <= 1 - Y); Y1 = (X >= 0 & X <= 1) & (Y >= sqrt(X) & Y <= 1) & (Z >= 0 & Z <= 1 - Y); Z1 = (X >= 0 & X <= 1) & (Y >= sqrt(X) & Y <= 1) & (Z >= 0 & Z <= 1 - Y); ineq1 = (X >= 0 & X <= 1) * 2; ineq2 = (Y >= sqrt(X) & Y <= 1) * 4; ineq3 = (Z >= 0 & Z <= 1 - Y) * 8; all = ineq1 & ineq2 & ineq3; colors = zeros(size(X))+ineq1+ineq2+ineq3; scatter3(X1(:),Y1(:),Z1(:),3,colors(:)','filled')
source share