How to plot feasible space in 3d, after subtracting multiple inequalities

Hi Guys,
I'm looking for a way to plot a feasible region in 3d space. The feasible region is defined by some inequalities, let's say:
- sqrt(xx.^2 + yy.^2 + zz.^2)<10
- xx.^2+yy.^2-zz<10
- x<2.5
The question is then: how to plot the volume that satisfies all inequalities?
I tried to use isosurface but i don't see how to use more inequalities with that....
Find below what i have so far... Thanks in Advance!
%%%%%%%%%%%%%%%%%
clear all;clc;close all;
%# create coordinates
[xx,yy,zz] = meshgrid(-15:15,-15:15,-15:15);
% boundary condition 1
rr = sqrt(xx.^2 + yy.^2 + zz.^2);
% plot boundary condition 1 with smaller values than 10
isosurface(xx,yy,zz,rr,10);hold on
% boundary condition 2
rr2 = xx.^2+yy.^2-zz;
% plot boundary condition 2 with smaller values than 10
isosurface(xx,yy,zz,rr2,10);
% boundary condition 3
rr3 = xx;
% plot boundary condition 3 with smaller values than 2.5
isosurface(xx,yy,zz,rr3,2.5);
axis equal

 Risposta accettata

Creating a binary 3d matrix does the job indeed. A 3d viewer code is not even necessary then... isosurface does the job:
clear all;clc;close all;
% density
n=.3;
% create coordinates
[xx,yy,zz] = meshgrid(-15:n:15,-15:n:15,-15:n:15);
% boundary condition 1
rr = sqrt(xx.^2 + yy.^2 + zz.^2);
% boundary condition 2
rr2 = xx.^2+yy.^2-zz;
% boundary condition 3
rr3 = xx;
% region
region3= rr<10 & rr2<10 & rr3<2.5;
p=patch(isosurface(region3,0.5))
set(p,'FaceColor','red','EdgeColor','none');
daspect([1,1,1])
view(3); axis equal
camlight
lighting gouraud
grid on
Thanks for your help!

1 Commento

I wasted all of Friday trying to do this. Got ahold of your code and had it working in half an hour. THANK YOU SO MUCH! (and my apologies if I'm not supposed to post thanks. Its a no-no on StackExchange)

Accedi per commentare.

Più risposte (1)

I would probably create a logical volume mask of the region,
region= rr<10 & rr2 < 10 & rr3<2.5
Then I would use a 3D viewer from the File Exchange to view "region". There are about a million posted there

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by