MATLAB Answers

dami
3

Blank areas with fill and patch in 2014b

Asked by dami
on 5 Nov 2014
Latest activity Commented on by Lisa Oberbroeckling on 14 Apr 2016
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

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:

Sign in to comment.

4 Answers

Answer by 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.
If you have more about your intent, please contact me at hull@mathworks.com so I can note it in our internal database.

  0 Comments

Sign in to comment.


Answer by dami
on 8 Nov 2014
Edited by 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.

  0 Comments

Sign in to comment.


Answer by 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.

  0 Comments

Sign in to comment.


Answer by Amro
on 4 Dec 2014
Edited by 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.

  0 Comments

Sign in to comment.