Opened 5 years ago

Last modified 5 years ago

#13072 assigned Bugs

boost::geometry::intersection different results for CCW and CW

Reported by: kle@… Owned by: Barend Gehrels
Milestone: To Be Determined Component: geometry
Version: Boost 1.64.0 Severity: Problem
Keywords: Cc:

Description

Hello,

when calculating the intersection between these two polygons the results differ dependent on the orientation (CW vs CCW).

#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/point_xy.hpp>

int main(int argc, char* argv[])
{
  typedef boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double>, true,  false >  boost_polygon_CW_Open;
  typedef boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double>, false, false > boost_polygon_CCW_Open;

  const std::string strPoly1( "POLYGON((986.53314901320903 603.61376367962623, 1014.6804499149767 602.74037774442763, 1018.1411735073581 623.97665453539310, 990.14493850604447 624.49725628790509))" );
  const std::string strPoly2( "POLYGON((986.77183669558929 603.60635741124452, 998.79457181965154 603.23330253835934, 1002.2613711877982 623.79581100129735, 990.30090761267468 624.02156931285253))" );

  boost_polygon_CW_Open p1_cw_open, p2_cw_open;
  boost::geometry::read_wkt(strPoly1, p1_cw_open);
  boost::geometry::read_wkt(strPoly2, p2_cw_open);
  boost::geometry::correct(p1_cw_open); // reverts order of points
  boost::geometry::correct(p2_cw_open); // reverts order of points

  std::vector<boost_polygon_CW_Open> output_cw;
  boost::geometry::intersection(p1_cw_open, p2_cw_open, output_cw); // correct: output_cw.front equals poly2

  boost_polygon_CCW_Open p1_ccw_open, p2_ccw_open;
  boost::geometry::read_wkt(strPoly1, p1_ccw_open);
  boost::geometry::read_wkt(strPoly2, p2_ccw_open);
  boost::geometry::correct(p1_ccw_open); // no modification
  boost::geometry::correct(p2_ccw_open); // no modification

  std::vector<boost_polygon_CCW_Open> output_ccw;
  boost::geometry::intersection(p1_ccw_open, p2_ccw_open, output_ccw); // incorrect: output_cw is empty!!!

  return 0;
}

Attachments (1)

examplePolys.png (11.1 KB ) - added by kle@… 5 years ago.
Plot of example polygons

Download all attachments as: .zip

Change History (2)

by kle@…, 5 years ago

Attachment: examplePolys.png added

Plot of example polygons

comment:1 by Barend Gehrels, 5 years ago

Status: newassigned
Note: See TracTickets for help on using tickets.