Plotting 3D regions with constraints on x,y and z.
4 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!