本文介绍了如何填写两行之间的区域和MATLAB中不直的曲线(该区域不是多边形)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用matlab的FILL函数创建一个由具有直边的多边形限定的填充区域:


不幸的是,在上图中留下了一个小的白色区域,因为我想填充的区域的边界in不是直边多边形,而是在左侧具有弯曲的边界。我有一条曲线(接近抛物线但不完全),我想填充两条水平线和曲线本身之间的区域。我还研究了MATLAB函数IMFILL,但没有运气。

解决方案

您需要做的是制作一个多边形,

 %#创建抛物线和两条直线
x = - 3:0.1:3;
y = x。^ 2/4;
plot(x,y)
hold,plot([ - 3 3],[1 1],'r',[ - 3 3],[2 2],'r')

%#创建一个拥抱抛物线的多边形
%#请注意,我们需要单独插入
%#来获得正数和负数x
x1 = interp1(y X&小于0),X(X&小于0),1:0.1:2);
%#反向插值,以便角正确排序
x2 = interp1(y(x> 0),x(x> 0),2:-0.1:1);

%#填满三条线所包围的区域
fill([x1,x2],[1:0.1:2,2:-0.1:1],'g')

Using matlab's FILL function creates a filled region confined by a polygon with straight edges:

Unfortunately this leaves a small white region in the figure above, because the boundary of the region I want filled in is not a straight-edged polygon, but rather has a curved boundary on the left side. I have a curve (nearly parabolic but not exactly), and I want to fill in the region between two horizontal lines AND the curve itself. I also looked into the MATLAB function IMFILL, but with no luck.

解决方案

What you need to do is make a polygon with more corners, so that it fits the curve more smoothly:

%# 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')

这篇关于如何填写两行之间的区域和MATLAB中不直的曲线(该区域不是多边形)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 07:33