代碼: 我正在使用boost_1_61_0。我正在使用GIS應用程序庫的幾何部分。這個想法是找到定義區域內的點(在這種情況下是一個矩形)。這有時候但並非總是有效。下面是一個例子,其中的點應該是在矩形內,但不是...boost :: geometry :: within對於地理座標系中的點失敗---爲什麼?
我有以下的測試案例:
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <iostream>
#include <boost/geometry/io/wkt/wkt.hpp>
class wxPoint
{
public :
double getx() const
{
return m_x;
}
double gety() const
{
return m_y;
}
void setx(double in)
{
m_x = in;
}
void sety(double in)
{
m_y = in;
}
private:
double m_x;
double m_y;
};
BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET(
wxPoint,
double,
boost::geometry::cs::geographic<boost::geometry::degree>,
wxPoint::getx,
wxPoint::gety,
wxPoint::setx,
wxPoint::sety)
int main()
{
boost::geometry::model::polygon<wxPoint> poly;
boost::geometry::read_wkt("POLYGON((0 89, 180 89, 180 0, 0 0, 0 89))", poly);
wxPoint point;
point.setx(150);
point.sety(88);
bool within = boost::geometry::within(point, poly);
return 0;
}
我希望within
是true
但它是false
。爲什麼它是false
?
只需要注意,如果有人認爲在88處y的點可能有點極端,那麼它也會失敗,例如y = 50. –