How to build 3d inequalities on matlab

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') 
0
source share
2 answers

You can do almost the same thing as in the case of 2d to which you are attached. Just write down your three inequalities, use a 3D grid, multiply each inequality by a number from a set of three numbers that has unique sums of the subset (e.g. 2, 4, 8) and uses 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') 
0
source

I am trying to figure out the same thing, and the trick is to make the size of everything that is not at the intersection 0. While Tobobal scatter3 line uses "3" as an option for the size, that is, all points will be displayed as a dot 3. This can be replaced by an equal-sized matrix by X1 with a set of sizes. The easiest way to do this is simply to do s = 3 * all:

 all = ineq1 & ineq2 & ineq3; colors = zeros(size(X))+all; sizes = 3 * all; scatter3(X1(:),Y1(:),Z1(:),sizes,colors(:)','filled') 

This should make you only the area at the intersection.

- Change: the color variable should also change. You just need intersection, not other inequalities.

0
source

Source: https://habr.com/ru/post/1439366/


All Articles