Boost logo

Geometry :

Subject: [geometry] Unexpected results with spherical polygon
From: Serge Monkewitz (smm_at_[hidden])
Date: 2015-01-12 14:57:13


Hi all,

  I’m completely new to boost::geometry, and am getting some unexpected results for a spherical polygon (test program below) with boost 1.56.0. Here’s the setup: I’ve got a polygon p with a single ring [v1, v2, v3, …, vn, v1]. If I then call within() using a point that is inside the corresponding (for lack of a better term) anti-polygon, within() returns true when I expect false. By anti-polygon, I mean the polygon that is defined by the points on the unit sphere that are directly across from the originals. What am I doing wrong / misunderstanding?

Thanks for any help,
Serge

————

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

using namespace boost::geometry;

typedef model::point<double, 2, cs::spherical_equatorial<degree> > spoint;
typedef model::polygon<spoint> spoly;

int main() {
   spoly p1;
   append(p1, spoint(350.0, 0.0));
   append(p1, spoint(0.0, -10.0));
   append(p1, spoint(10.0, 0.0));
   append(p1, spoint(0.0, 10.0));
   correct(p1);
   std::cout << "(0.0, 0.0): " << within(spoint(0.0, 0.0), p1) << std::endl;
   std::cout << "(5.0, 0.0): " << within(spoint(5.0, 0.0), p1) << std::endl;
   std::cout << "(-5.0, 0.0): " << within(spoint(-5.0, 0.0), p1) << std::endl;
   std::cout << "(0.0, 5.0): " << within(spoint(0.0, 5.0), p1) << std::endl;
   std::cout << "(0.0, -5.0): " << within(spoint(0.0, -5.0), p1) << std::endl;
   std::cout << "(45.0, 0.0): " << within(spoint(45.0, 0.0), p1) << std::endl;
   std::cout << "(0.0, 45.0): " << within(spoint(0.0, 45.0), p1) << std::endl;
   std::cout << "(180.0, 0.0): " << within(spoint(180.0, 0.0), p1) << std::endl;
   std::cout << "(180.0, 5.0): " << within(spoint(180.0, 5.0), p1) << std::endl;
   std::cout << "(180.0, -5.0): " << within(spoint(180.0, -5.0), p1) << std::endl;
   std::cout << "(175.0, 0.0): " << within(spoint(175.0, 0.0), p1) << std::endl;
   std::cout << "(185.0, 0.0): " << within(spoint(185.0, 0.0), p1) << std::endl;
}
————
This prints:

(0.0, 0.0): 1
(5.0, 0.0): 1
(-5.0, 0.0): 1
(0.0, 5.0): 1
(0.0, -5.0): 1
(45.0, 0.0): 0
(0.0, 45.0): 0
(180.0, 0.0): 1
(180.0, 5.0): 1
(180.0, -5.0): 1
(175.0, 0.0): 1
(185.0, 0.0): 1
————


Geometry list run by mateusz at loskot.net