
Geometry : 
Subject: [ggl] Point in triangle test available?
From: Hartmut Kaiser (hartmut.kaiser)
Date: 20101201 21:44:55
> > Does Boost.Geometry have a precanned 'point in triangle' test
> > available? I could come up with one myself easily, but asking might
> > allow me to stay lazy :P
>
> There is point in polygon, of course. I'm not sure of the syntax
> required, however.
For the sake of simplicity, I implemented this function for my use case:
// check, whether (x, y) is inside the triangle spanned by
// [(x1, y1), (x2, y2), (x3, y3)]
inline bool
is_point_in_triangle(double x, double y, double x1, double y1,
double x2, double y2, double x3, double y3)
{
namespace bg = boost::geometry;
typedef bg::model::point_xy<double> /*_ll_deg*/ point_type;
// typedef bg::longitude<double> longitude;
// typedef bg::latitude<double> latitude;
bg::model::polygon<point_type> poly;
poly.outer().push_back(point_type(x1, y1/*longitude(x1),
latitude(y1)*/));
poly.outer().push_back(point_type(x2, y2/*longitude(x2),
latitude(y2)*/));
poly.outer().push_back(point_type(x3, y3/*longitude(x3),
latitude(y3)*/));
bool orient = bg::area(poly) >= 0 ? true : false;
point_type p(x, y/*longitude(x), latitude(y)*/);
return bg::within(p, poly) ? orient : !orient;
}
It compiles fine as long as I use a point_xy<double>, but fails to compile
the algorithms when using point_ll_deg as the point type. Is that not
implemented yet? Or did I miss some header file for the concept mapping?
Regards Hartmut

http://boostspirit.com
Geometry list run by mateusz at loskot.net