polybool function works wrong
조회 수: 5 (최근 30일)
이전 댓글 표시
Looks like the polybool function can give completely wrong results in some cases. The simplest example is the following:
p1x = [-0.38638747761632497000 0.19712615255652799000 0.11632212129588278000];
p1y = [-0.19990841690264510000 0.44255449769997601000 -0.32295394513363201000];
p2x = [-0.63774227707713371000 0.09164976063543484000 0.61903172020561337000];
p2y = [-0.13838565278600026000 0.66469299048631436000 -0.44599947336401247000];
[p3x p3y] = polybool('-', p1x,p1y, p2x, p2y);
figure;
hold on
plot(p1x([1:end 1]), p1y([1:end 1]), 'o-black')
plot(p2x([1:end 1]), p2y([1:end 1]), '.-g')
plot(p3x([1:end 1]), p3y([1:end 1]), '*-r')
Here the subtranction should give empty polygon, while it gives something strange (see red polygon)...
So the question is: are there any alternatives for polybool function for subtracting and merging polygons?
댓글 수: 0
답변 (4개)
Kelly Kearney
2015년 5월 5일
편집: Kelly Kearney
2015년 5월 5일
I see the correct empty result in R2015a, but the same not-quite-right results that I assume the original poster was seeing when I try the example in R2013a.
So if you have the option of updating to R2015a, try that first. Otherwise, you might try looking at these options on the FEX: Polygon Clipper (which uses the same underlying GPC library as polybool, or Polygon Clipping and Offsetting, which uses a different mexed library.
댓글 수: 0
Nalini Vishnoi
2015년 5월 5일
편집: Nalini Vishnoi
2015년 5월 5일
Hi Dmitry,
Which version of MATLAB are you currently using? I tried the sample code in MATLAB R2013b (and later versions) and it returned p3x and p3y as empty arrays (which is the expected answer). However, it looks like there was some issue with versions between R2009b and R2013a and the sample code returns unexpected results of polybool subtraction in these versions. Again, the versions before R2009b (R2009a and earlier) return the correct expected result.
Please try the sample code on a recent version of MATLAB and confirm this.
Thanks, Nalini
댓글 수: 0
Dmitry
2015년 5월 6일
댓글 수: 1
Kelly Kearney
2015년 5월 6일
Interesting. The problem definitely seems to be due to the duplicated point. My license for 2012a isn't valid anymore, so I can't test that, but the code for polybool.m doesn't appear to have changed at all between the two versions, nor does any of the code in the setup subfunctions ( checkxy.m, vectorsToGPC.m, etc). However, the gpcmex file itself seems significantly smaller in 2012a than in 2015a, so something must have changed under the hood there.
Are these examples you're posting typical ones for your application? Because they seem to be pushing the limits of polygon clipping algorithms. Perhaps adding filters to check for and remove unnecessary duplicated vertices will help. If these are typical input data, though, you might want to rethink your overall algorithm.
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!