如何填写在该地区两条线和曲线直不是在MATLAB之间(该区域不是多边形)(How do I fill

2019-07-31 06:05发布

用matlab的填充函数创建了由直边的多边形限制填充区域:

不幸的是这个叶上图中一个白色的小区域,因为我要填补该地区的边界不是直边的多边形,而是对左侧弯曲的边界。 我有一个曲线(近抛物线但不完全),我想两个水平线条和曲线本身之间填充的区域。 我也看了到MATLAB功能IMFILL,但没有运气。

Answer 1:

你需要做的是让更多的四个角的多边形,所以它适合曲线更流畅:

%# create a parabola and two straight lines
x = -3:0.1:3;
y = x.^2/4;
plot(x,y)
hold on, plot([-3 3],[1 1],'r',[-3 3],[2 2],'r')

%# create a polygon that hugs the parabola
%# note that we need to interpolate separately
%# for positive and negative x
x1 = interp1(y(x<0),x(x<0),1:0.1:2);
%# interpolate in reverse so that the corners are properly ordered
x2 = interp1(y(x>0),x(x>0),2:-0.1:1);

%# fill the area bounded by the three lines
fill([x1,x2],[1:0.1:2,2:-0.1:1],'g')



文章来源: How do I fill in the area between two lines and a curve that's not straight in MATLAB (the region is not a polygon)