相关疑难解决方法(0)

四叉树最近邻算法

我已经实现了 n 个点的四叉树结构以及返回给定矩形内的点数组的方法。我似乎无法找到一种算法来有效地找到最接近另一个给定点的点。我错过了一些明显的东西吗?我认为递归解决方案是正确的方法吗?

我正在使用 Objective C,但伪代码就可以了。此外,我实际上存储了经纬度数据,并且点之间的距离沿着一个大圆。

编辑: 这是我的树插入和细分代码

- (BOOL)insert:(id<PASQuadTreeDataPoint>)dataPoint {

    BOOL pointAdded = false;

    // If the point lies within the region
    if(CGRectContainsPoint(self.region, dataPoint.point)) {

        // If there are less than 4 points then add this point
        if(self.dataPoints.count < kMaxPointsPerNode) {
            [self.dataPoints addObject:dataPoint];
            pointAdded = true;
        }
        else {

            // Subdivide into 4 quadrants if not already subdivided
            if(northEast == nil) [self subdivide];

            // Attempt to add the point to one of the 4 subdivided quadrants
            if([northEast insert:dataPoint]) return …
Run Code Online (Sandbox Code Playgroud)

algorithm quadtree geolocation nearest-neighbor

5
推荐指数
1
解决办法
1万
查看次数