Boost C++ Libraries: Ticket #6696: boost::geometry::intersection on two triangles creates self-intersecting polygon https://svn.boost.org/trac10/ticket/6696 <p> The code below creates two triangles sharing one vertex, intersects them, and then tests the result for self intersections. The test fails on 1.49.0. </p> <p> #include &lt;iostream&gt; #include &lt;deque&gt; </p> <p> #include &lt;boost/geometry.hpp&gt; #include &lt;boost/geometry/geometries/point_xy.hpp&gt; #include &lt;boost/geometry/geometries/polygon.hpp&gt; #include &lt;boost/geometry/io/wkt/wkt.hpp&gt; #include &lt;boost/geometry/multi/geometries/register/multi_polygon.hpp&gt; </p> <p> typedef boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double&gt;,false&gt; polygon; BOOST_GEOMETRY_REGISTER_MULTI_POLYGON(std::deque&lt;polygon&gt;); </p> <p> int main() { </p> <blockquote> <p> polygon green, blue; std::deque&lt;polygon&gt; output; </p> </blockquote> <blockquote> <p> boost::geometry::read_wkt( </p> <blockquote> <p> "POLYGON((0.94458145927637815475 0.76153991837054491043 , 0.37399105052463710308 0.59515245421789586544 , " "0.031151068862527608871 0.95449111564084887505 , 0.94458145927637815475 0.76153991837054491043))", green); </p> </blockquote> </blockquote> <blockquote> <p> boost::geometry::read_wkt( </p> <blockquote> <p> "POLYGON((0.94458145927637815475 0.76153991837054491043 , 0.90063317718199253914 0.7487243450636832387 , " "0.57996011668279578988 0.83856179693083876536 , 0.94458145927637815475 0.76153991837054491043))", blue); </p> </blockquote> </blockquote> <blockquote> <p> boost::geometry::intersection(blue, green, output); </p> </blockquote> <blockquote> <p> std::cout&lt;&lt;"testing output"&lt;&lt;std::endl; </p> </blockquote> <blockquote> <p> boost::geometry::detail::overlay::has_self_intersections(output); </p> </blockquote> <blockquote> <p> std::cout&lt;&lt;"valid output"&lt;&lt;std::endl; </p> </blockquote> <blockquote> <p> return 0; </p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6696 Trac 1.4.3 Barend Gehrels Thu, 22 Mar 2012 18:32:49 GMT status, milestone changed; resolution set https://svn.boost.org/trac10/ticket/6696#comment:1 https://svn.boost.org/trac10/ticket/6696#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.50.0</span> </li> </ul> <p> Thanks for your report. </p> <p> This has been solved in the meantime one or two weeks ago, in Boost.Trunk. Polygons with less then 3 points or an area of 0.0 are filtered out. This solves this issue. </p> Ticket snubdodecahedron@… Fri, 23 Mar 2012 11:06:57 GMT <link>https://svn.boost.org/trac10/ticket/6696#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6696#comment:2</guid> <description> <p> I updated to the trunk a few hours ago. I am hitting the same problem but this time on a different set of input polygons. Thanks for your time. </p> <p> Craig </p> <pre class="wiki">#include &lt;cstdio&gt; #include &lt;vector&gt; #include &lt;boost/geometry.hpp&gt; #include &lt;boost/geometry/geometries/point_xy.hpp&gt; #include &lt;boost/geometry/geometries/polygon.hpp&gt; #include &lt;boost/geometry/geometries/register/point.hpp&gt; #include &lt;boost/geometry/geometries/register/ring.hpp&gt; #include &lt;boost/geometry/io/wkt/wkt.hpp&gt; #include &lt;boost/geometry/multi/geometries/multi_polygon.hpp&gt; typedef boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double&gt; &gt; polygon; typedef boost::geometry::model::multi_polygon&lt;polygon&gt; multi_polygon; int main() { polygon green, blue; multi_polygon output; boost::geometry::read_wkt( "POLYGON((0.63872330997599124913 0.25963790394761232516 , 0.51901482278481125832 0.36860892060212790966 , 0.24443514109589159489 0.62663296470418572426 , 0.41175117865081167778 0.47178476291601745274 , 0.63872330997599124913 0.25963790394761232516))", green); boost::geometry::read_wkt( "POLYGON((0.52364358028948876367 0.36823021165656988352 , 0.7762673462275415659 0.13443113025277850237 , 0.59446187055393329146 0.29992923303868185281 , 0.52364358028948876367 0.36823021165656988352))", blue); boost::geometry::correct(green); boost::geometry::correct(blue); boost::geometry::detail::overlay::has_self_intersections(green); boost::geometry::detail::overlay::has_self_intersections(blue); printf("A\n"); boost::geometry::intersection(green,blue,output); printf("B\n"); boost::geometry::detail::overlay::has_self_intersections(output); printf("C\n"); return 0; } </pre> </description> <category>Ticket</category> </item> </channel> </rss>