Unexpected results with spherical polygon

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Unexpected results with spherical polygon

Serge Monkewitz
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 mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unexpected results with spherical polygon

Serge Monkewitz
Hi all,

    Sorry to bump this thread - is there some other place I should report what I think may be a bug?

Regards,
Serge

On Jan 12, 2015, at 11:57 AM, Serge Monkewitz <[hidden email]> wrote:

> 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 mailing list
> [hidden email]
> http://lists.boost.org/mailman/listinfo.cgi/geometry

_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry
Loading...