Blank areas with fill and patch in 2014b
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
Lisa Oberbroeckling
2016-4-14
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:
回答(4 个)
Doug Hull
2014-11-6
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 个评论
Image Analyst
2014-11-8
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 个评论
Amro
2014-12-4
编辑:Amro
2014-12-4
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Triangulation Representation 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!