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

조회 수: 5 (최근 30일)
Edwin
Edwin 2022년 11월 29일
답변: Jonas 2022년 11월 29일
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