# Blank areas with fill and patch in 2014b

32 views (last 30 days)
dami on 5 Nov 2014
After updating to version 2014b, my code containing fill or patch functions does not work properly. Try this example:
poly=[
6.00 0.00
6.00 4.00
7.00 5.00
8.00 5.00
8.00 0.50
9.00 0.50
9.00 5.00
7.00 5.00
8.00 6.00
9.50 5.00
9.50 0.50
10.0 0.50
10.0 0.00
9.50 0.00
6.00 0.00];
fill(poly(:,1),poly(:,2),'r')
The internal area is not filled properly, and the problem seems related to polygons with holes. In Matlab 2014a everything was ok.

#### 1 Comment

Lisa Oberbroeckling on 14 Apr 2016
I've asked students to program their own Riemann Sum demo for years. Previous to R2014b, the following example code would work fine. Since then, it has the blank areas as discussed above. Taking out redundant vertices or adding vertices to "close the rectangles" does not help. Now the students have to use the fill command on each individual rectangle within their loops, as suggested by Image Analyst. This is unfortunate since we've been discussing "vectorization of code" in previous assignments. Any thoughts on when or if this may be fixed?
x=[0 0 1 1 1 1 2 2 2 2 3 3 3 3 4 4];
y=[0 1 1 0 0 2 2 0 0 3 3 0 0 4 4 0];
fill(x,y,'b')
Created using R2014a:
Created using R2015a:

Doug Hull on 6 Nov 2014
Thank you for this simple reproduction case. Our developers in this area have noted this:
Our current rule for in-out test is a purely topological test based on Jordan-curve. Crossing of a single edge represents a flip in parity. Crossing of a double overlapping edge is ignored and does not change parity – such an edge is typically a bridge-edge that connects outer and inner loops – inner ones being holes.

dami on 8 Nov 2014
Edited: dami on 8 Nov 2014
The problem is that even if there is no intersection with the edges, as in my example, the area is not filled properly: the white triangle is not bordered by any edge, and it should be filled according to Jordan curve theorem.
It seems a technical issue, because moving slightly some points this blank area disappears.

Image Analyst on 8 Nov 2014
I suggest that whenever you have polygons where the edge intersects or crosses another edge, you plot it as two or more separate regions.

Amro on 4 Dec 2014
Edited: Amro on 4 Dec 2014
The problem happens after the patch face is internally triangulated , when deciding which triangles are filled vs. holes. Try the following:
dt = delaunayTriangulation(poly);
triplot(dt)
text(poly(:,1), poly(:,2), cellstr(num2str((1:size(poly,1))')), ...
'Color','m', 'HorizontalAlign','left', 'VerticalAlign','bottom')
You can see that the triangle (2,3,4) corresponds to the one not filled in your example...
A simple workaround is to nudge the coordinates of the shared vertex 8, e.g:
poly(8,2) = poly(8,2) + 1e-6;
The offset is too small for you notice, but it should fix the bug for now.

### Community Treasure Hunt

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

Start Hunting!

Translated by