Plotting 3D regions with constraints on x,y and z.

조회 수: 5 (최근 30일)
Jeff
Jeff 2011년 10월 8일
Hello,
I am trying to plot 3D solid regions based on certain constraints for x,y and z. Just as an example, the region of space bounded by 0<=x<=1, 0<=y<=2, 0<=z<=3 should obviously plot a rectangular prism, but my bounds may be more complicated such as: 0<=x<=1, x^2<=y<=x, 0<=z<=x+sqrt(y) .
How might I go about tackling this sort of problem? Any help would be appreciated.

채택된 답변

Dr. Seis
Dr. Seis 2011년 10월 8일
I have done some 3D shapes in the past. It may not be pretty, but it may be an option unless others have more efficient ways of coding. You will notice that the conditions you outlined above are "hard coded" into the function - anyone else have an idea how to make it more general (i.e., conditions defined as input arguments)? You can make the object more smooth by reducing the "dxyz" increment. I also have things in here that can change the way the object is illuminated, shaded, and colored. You will have to play around until you like the result.
Create and save this as an .m file, then run:
function plot_this
dxyz = 0.1;
x = 0 : dxyz : 1;
X = [];
for i = 1 : length(x)
y = x(i)^2;
while y <= x(i)
if isempty(X)
X(1,:) = [x(i),y,0];
X(2,:) = [x(i),y,x(i)+sqrt(y)];
else
X(end+1,:) = [x(i),y,0];
X(end+1,:) = [x(i),y,x(i)+sqrt(y)];
end
y = y + dxyz;
end
end
X = unique(X,'rows')
options = {'Qt','Qbb','Qc'};
Tes = delaunay3(X(:,1),X(:,2),X(:,3),options);
tetramesh(Tes,X);
colormap(white);
face_alpha = 1.0;
alpha(face_alpha)
shading flat
axis equal
light('Position',[-0.58674 -0.05336 0.80801],'Style','infinite')
light('Position',[-0.58674 -0.05336 -0.80801],'Style','infinite')
  댓글 수: 2
Dr. Seis
Dr. Seis 2011년 10월 8일
I edited to remove any rows in "X" that might repeat.
Jeff
Jeff 2011년 10월 9일
Thanks very much. This worked quite well for me. I agree that with only small tweaks (keeping the basic structure you present in place), it may be made more flexible so that it could support a generic constraint of the form
a<=x<=b, f(x)<=y<=g(x), u(x,y)<=z<=v(x,y).
The function could be passed a,b,f(x),g(x),u(x,y),v(x,y) and the ordering of x,y,z to arrive at the desired result... I'll have to try it!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by