本文整理汇总了C++中PointType::cartesian方法的典型用法代码示例。如果您正苦于以下问题:C++ PointType::cartesian方法的具体用法?C++ PointType::cartesian怎么用?C++ PointType::cartesian使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PointType
的用法示例。
在下文中一共展示了PointType::cartesian方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: simpleDistance
// Use squared distances in order to avoid computing square roots
double simpleDistance(PointType a, PointType b)
{
double sum = 0.0;
for (int i = 0 ; i < dimensions ; i++)
{
double factor = a.cartesian(i) - b.cartesian(i);
sum += factor * factor;
}
return sum;
}
示例2: search
// The code is based on the algorithm described here:
// http://en.wikipedia.org/wiki/K-d_tree#Nearest_neighbour_search
PointType search(Node* currentRoot, PointType& queryPoint)
{
// Return dummy point
if ( currentRoot == NULL ) return PointType(dimensions, CGAL::ORIGIN);
int level = currentRoot->level;
Node* branchToFollow;
Node* otherBranch;
// Choose which path to follow, based on current level'th coordinate
if ( queryPoint.cartesian(level) < currentRoot->point.cartesian(level) )
{
branchToFollow = currentRoot->less;
otherBranch = currentRoot->greater;
}
else
{
branchToFollow = currentRoot->greater;
otherBranch = currentRoot->less;
}
// Leaf node reached. A leaf node is a node that has no children in the desired direction
if ( branchToFollow == NULL )
{
double currentDistance = simpleDistance(currentRoot->point, queryPoint);
// First leaf encountered
if ( currentBestDistance < 0 )
{
currentBest = currentRoot->point;
currentBestDistance = currentDistance;
}
else if ( currentDistance < currentBestDistance )
{
currentBest = currentRoot->point;
currentBestDistance = currentDistance;
}
}
else
{
search(branchToFollow, queryPoint);
// Compare currentBest with the currentRoot while unwinding the recursion
double currentDistance = simpleDistance(currentRoot->point, queryPoint);
if ( currentDistance < currentBestDistance )
{
currentBest = currentRoot->point;
currentBestDistance = currentDistance;
}
}
// Check if there can be any candidate points on the other side of the splitting plane
// that can be closer to the queryPoint than the currentBest. In effect check
// whether a hypersphere with center the queryPoint and radius equal to the distance
// to the currentBest, crosses over the splitting plane.
// NOTE: currentBestDistance is a squared distance, and so the distance from the
// splitting plane is squared as well before the comparison.
double distanceFromSplit = queryPoint.cartesian(level) - currentRoot->point.cartesian(level);
if ( (distanceFromSplit * distanceFromSplit) < currentBestDistance )
search(otherBranch, queryPoint);
return currentBest;
}
示例3: operator
bool operator() (PointType p1, PointType p2) { return p1.cartesian(dimension) < p2.cartesian(dimension);}