How can we fill a region defined by a implicit function?
10 次查看(过去 30 天)
显示 更早的评论
I use fimplicit(f, -10,10,-10,10) to plot the curve
where
. How can I color the region in which
from the rectangle
?
where
. How can I color the region in which
from the rectangle
?I know a solution which is not that precise:
f=@(x,y) sin(x)*sin(y)-0.5;
x=linspace(a1,b1,100);
y=linspace(a2,b2,100);
[X,Y]=meshgrid(x,y);
condition=f(X,Y)>=0;
output=zeros(Nx,Ny);
output(~(condition))=1;
imshow(output, 'xdata', x, 'ydata', y);
axis on;
I don't know why the y-axis is reversed in that situation,and it appears smaller or greater depending on the length of x and y. Moreover I don't know how to use other colors than black and white (see here https://www.mathworks.com/matlabcentral/answers/297554-how-can-i-plot-the-region-for-two-inequalities). Anyway, is there a solution which maybe use the points we get from fimplicit?
fp=fimplicit(f,-10,10,-10,10);
Points=[fp.Xdata;fp.Ydata];
Maybe using patch or fill commands...? It works fine with patch if I have a connected curve, but this is not the case.
In Wolfram Alpha I just write f(x,y)>0 and the region is ploted. I wonder if there is such a code for Matlab too.
采纳的回答
Star Strider
2021-4-17
编辑:Star Strider
2021-4-17
I am not certain what you want.
Try this:
f=@(x,y) sin(x).*sin(y)-0.5;
figure
fp1=fimplicit(f,[-10,10,-10,10]);
hold on
fp2=fcontour(f,[0,10,0,10]);
fp2.LevelList = [0 0];
fp2.Fill = 'on';
colormap([1 1 1; 0 1 0])
hold off
.
EDIT — (17 Apr 2021 at 19:43)
Another option:
f=@(x,y) sin(x).*sin(y)-0.5;
figure
fp1=fimplicit(f,[-10,10,-10,10]);
hold on
fp2=fcontour(f,[0,10,0,10]);
fp2.LevelList = linspace(0, 0.5, 25);
hold off
.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!