예제 #1
0
static FlatGeoPoint
segment_nearest_point(const SearchPointVector& spv,
                      const SearchPointVector::const_iterator i1,
                      const FlatGeoPoint &p3)
{
  if (i1+1 == spv.end()) {
    return nearest_point(i1->get_flatLocation(),
                         spv.begin()->get_flatLocation(),
                         p3);
  } else {
    return nearest_point(i1->get_flatLocation(),
                         (i1+1)->get_flatLocation(),
                         p3);
  }
}
예제 #2
0
GeoPoint 
AirspacePolygon::closest_point(const GeoPoint& loc) const
{
  const FlatGeoPoint p = m_task_projection->project(loc);
  const FlatGeoPoint pb = nearest_point(m_border, p, m_is_convex); 
  return m_task_projection->unproject(pb);
}
예제 #3
0
int CSkitchComponent::GetNearestSkitchPoint( Mth::Vector *p_point, Mth::Vector &pos )
{
	int nearest_node_number = -1;	// -1 means not found yet

	// Only continue if we have a parent object (we always should) and a object hook manager component.
	CCompositeObject *p_parent_object = GetObject();
	if( mp_object_hook_manager_component && p_parent_object )
	{
		Obj::CObjectHookManager *p_object_hook_man = mp_object_hook_manager_component->GetObjectHookManager();
		if( p_object_hook_man )
		{
			// Form a transformation matrix.
			Mth::Matrix total_mat	= p_parent_object->GetMatrix();
			total_mat[X][W]			= 0.0f;
			total_mat[Y][W]			= 0.0f;
			total_mat[Z][W]			= 0.0f;
			total_mat[W]			= p_parent_object->GetPos();
			total_mat[W][W]			= 1.0f;

			p_object_hook_man->UpdateTransform( total_mat );

			int node_number = 0;
			CObjectHookNode *p_node		= p_object_hook_man->GetFirstNode();
			CObjectHookNode *p_nearest	= p_node;
			float nearest_dist_squared	= 100000000000000.0f;	
			Mth::Vector nearest_point(0.0f, 0.0f, 0.0f);

			while( p_node )
			{
				// Get the postition of the hook.
				Mth::Vector point = p_object_hook_man->GetPos( p_node );

				// Project the point onto the base plane of the object so we can ignore the height.
				point -= p_parent_object->GetPos();
				point.ProjectToPlane( p_parent_object->GetMatrix()[Y] );
				point += p_parent_object->GetPos();
			
				float dist_squared = ( point - pos ).LengthSqr();
				if( dist_squared < nearest_dist_squared )
				{
					nearest_dist_squared	= dist_squared;
					nearest_point			= point;
					p_nearest				= p_node; 
					nearest_node_number		= node_number;
				}
				p_node = p_node->GetNext();
				node_number++;
			}		
			*p_point = nearest_point;
		 }
	}

	return nearest_node_number;
}