当前位置: 首页>>代码示例>>C++>>正文


C++ PointType::cartesian方法代码示例

本文整理汇总了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;
		}
开发者ID:gkastrinis,项目名称:KD-tree---Nearest-Neighbour,代码行数:11,代码来源:KD_tree.hpp

示例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;
		}
开发者ID:gkastrinis,项目名称:KD-tree---Nearest-Neighbour,代码行数:65,代码来源:KD_tree.hpp

示例3: operator

		bool operator() (PointType p1, PointType p2) { return p1.cartesian(dimension) < p2.cartesian(dimension);}
开发者ID:gkastrinis,项目名称:KD-tree---Nearest-Neighbour,代码行数:1,代码来源:KD_tree.hpp


注:本文中的PointType::cartesian方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。