请给我一些关于如何评估覆盖所有给定区域的最大区域的建议?
假设我有几十个地理区域,可以通过使用以下 c/c++ 结构来定义:
typedef struct tagGEOGRAPHIC_REGION
{
float fNorthMost;
float fSouthMost;
float fWestMost;
float fEastMost;
} GEOGRAPHIC_REGION, *PGEOGRAPHIC_REGION;
现在我想要获得最大区域,它将覆盖所有给定区域。函数模板可能如下所示:
const GEOGRAPHIC_REGION& GetMaxRegion(const std:vector<GEOGRAPHIC_REGION>& vRegions)
{
......
}
我可以将 GEOGRAPHIC_REGION 结构体的四个组成部分放入 4 个不同的浮点向量中,然后计算它们各自的最大值。最后,可以将四个最大值组合起来形成最大值区域。我认为这一定是一个简单的方法。您能给我一些建议吗?非常感谢!
Suppose I have dozens of geographic regions, which can be defined through the use of the following c/c++ structure:
typedef struct tagGEOGRAPHIC_REGION
{
float fNorthMost;
float fSouthMost;
float fWestMost;
float fEastMost;
} GEOGRAPHIC_REGION, *PGEOGRAPHIC_REGION;
And I now want to get the maximum region, which will cover all given regions. The function template may look like the following:
const GEOGRAPHIC_REGION& GetMaxRegion(const std:vector<GEOGRAPHIC_REGION>& vRegions)
{
......
}
I can put the four components of GEOGRAPHIC_REGION struct into 4 different float vectors, and then evaluate their respective maximum values. Finally, the four maxium values can be combined to form the maximum region. I think it must be a simple way to do that. Would you please give me some advice? Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
难道你不能只迭代向量,并仅用一个循环获得最大北、最小南等吗?
Can't you just iterate over the vector, and get the maximum north, minimum south, etc, with just one loop?
我建议以这样的方式作为起点:
请注意,我可能猜错了你的轴方向(在这种情况下,你可能需要交换一些最小/最大)编辑根据评论修复“北是正,东为正”对于向量,只需执行
std::acummulate(v.begin(), v.end(), v [0]....)
如果您的场景变得更复杂,请参阅 Boost 几何库
。
I suggest something like this as a starting point:
note that I might have your axis direction guessed wrong (you might need to swap some min/max in that case)Edit fixed according to comment "North is positive, and East is positive"for a vector, just do
std::acummulate(v.begin(), v.end(), v[0]....)
In case your scenarios get more complicated, see the Boost Geometry Library
.