How do I plot grid points in a wedge-shaped volume?

2 次查看(过去 30 天)
In the below code, how do I modify so that it gives me 3D plot of grid points? Right now I am only getting 2D plot.
yq=repmat(-10:10,100);
xq=repmat(-10:10,100)';
r=10;
teta=0:0.01:pi/6;
teta1=pi/4;
xv=[0 r*cos(teta)];
yv=[0 r*sin(teta)];
zv=0:.1:10;
[in,on] = inpolygon(xq,yq,xv,yv);
h=10^-10;
a=numel(in);
b=a*10/h;
sz=0.3;
figure (1)
plot(xv,yv) % polygon
axis equal
hold on
plot(xq(in),yq(in),'r+') % points inside
plot(xq(~in),yq(~in),'bo') % points outside
hold on
figure (2)
[X,Y,Z]=meshgrid(xv,yv,zv);
hold off

回答(1 个)

Jonas
Jonas 2022-11-29
you could add the third dimension like that:
x=-6:6;
[X,Y,Z]=meshgrid(x);
r=5;
phi=pi/2; % from [0,pi]
theta=pi/4; % from [0,2pi)
Xin=X<=sin(phi)*cos(theta);
Yin=Y<=sin(phi)*sin(theta);
Zin=Z<=cos(phi);
allIn=Xin & Yin & Zin & (sqrt(X.^2+Y.^2+Z.^2)<=r);
plot3(X(allIn),Y(allIn),Z(allIn),'ro','MarkerFaceColor','r')
hold on;
plot3(X(~allIn),Y(~allIn),Z(~allIn),'b.')
hold off;
xlabel('x'); ylabel('y'); zlabel('z');
view(-12.3,37.8)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by