最近邻搜索

时间:2015-03-15 01:16:02

标签: c++ kdtree

//returns a possible best nearest point 
void KDTree::search_KD(KDNode *r, XY point){

KDNode *currentNode; 
currentNode = r; 

//if the current location is better than the best known location 
if (distance(currentNode, point) < bestDistance){
    bestDistance = distance(currentNode, point); 
    //update the best known location 
    guess = currentNode; 
}

//when key = 0, compare x-values
if (root->key == 0){
    //recursively search the left subtree on the next axis
    if (point.getX() < currentNode->coordinates.getX()){
        search_KD(r->left, point);
    }
    else {
        search_KD(r->right, point);
    }    
}

//when key = 1, compare y-values
if (root->key == 1){
    //recursively search the left subtree on the next axis
    if (point.getY() < currentNode->coordinates.getY()){
        search_KD(r->left, point);
    }
    else {
        search_KD(r->right, point);
    }    
}
}

我正在尝试实施最近邻搜索。我一直在使用此链接作为代码http://web.stanford.edu/class/cs106l/handouts/assignment-3-kdtree.pdf的主干。请参考第9页,所以我遇到的问题是实现最后一部分:如果半径为abs(point-currentNode)的圆与一个分裂平面相交。如果你看一下第9页代码部分的最后一行,它告诉我“递归搜索下一个轴上的另一个子树”,我将如何去做。如果回答的人提供了如何处理这一部分的建议,我将不胜感激。

注意:我将guess和bestDistance声明为全局变量,如文档所示。

0 个答案:

没有答案