我的大脑今天不工作了。我需要测试一个点(纬度、经度)是否位于 map 上的矩形内。矩形由它的北、东、南和西边界定义。问题是所有点或值都在 map 坐标系中。为了处理日期变更线环绕,我假设如果我们从左到右,经度总是“介于”之间。
bool PointInRectangle(Point pt, double North, double East, double South, double West)
{
// ????
}
最佳答案
假设东和北为正:
bool PointInRectangle(Point pt, double North, double East, double South, double West)
{
// you may want to check that the point is a valid coordinate
if (West < East)
{
return pt.X < East && pt.X > West && pt.Y < North && pt.Y > South;
}
// it crosses the date line
return (pt.X < East || pt.X > West) && pt.Y < North && pt.Y > South;
}
关于c# - 使用 map 坐标确定点是否在矩形中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10657098/