3d coordinates + shade

2019-07-15 11:14发布

I am trying to plot a 3D coordinate system (X,Y,Z) and then I would like to shade an area within this 3D coordinate system with some color for example shade the following region defined by:

Z > Y > X

Can anyone please help?

I have done the following but cant seem to know how to proceed,

a=0:0.1:10;
b=0:0.1:10;
c=0:0.1:10;
[x,y,z]=meshgrid(a,b,c);

2条回答
Juvenile、少年°
2楼-- · 2019-07-15 11:29

Depending on what you call shading, this can be a starting point:

Create a 3D grid of points and a logical 3D array satisfying your condition:

[X,Y,Z] = meshgrid(1:100,1:100,1:100);
ShadeRegion=(Z > Y).*(Y> X);

Then use the built-in function isosurface:

fv = isosurface(X,Y,Z,ShadeRegion,0.5);

You can then apply the example in displaying isosurfaces available in the manual:

p=patch(fv);
set(p,'FaceColor','red','EdgeColor','none');
daspect([1,1,1])
view(3); axis tight
camlight 
lighting gouraud

Result:

shaded region

查看更多
迷人小祖宗
3楼-- · 2019-07-15 11:45

Ok, so you need to be able to plot volumetric data then. The best thing you can do is download vol3d in order to achieve that. Its a quite nice voxel visualizer.

then:

a=0:0.1:10;
b=0:0.1:10;
c=0:0.1:10;
[x,y,z]=meshgrid(a,b,c);

shaded_area=false(size(x));

% Your rules

shaded_area=y>x;           % two ways ;).
shaded_area(z>y)=true;

% Plot it!
vol3d('Cdata',shaded_area);

However, as you are triying to plot volumetric boolean data I suggest you use this couple of nice things in order to get a "nicer" visualization, no more.

vol3d('Cdata',smooth3(uint8(shaded_area),'gaussian'))
axis([0 length(a) 0 length(b) 0 length(c)])
view(122,14)
axis off

enter image description here

查看更多
登录 后发表回答