Ejemplo n.º 1
0
//line triangle intersections
Eigen::Vector3d Triangle::shortestDistanceTo(Eigen::Vector3d line_segment_start, Eigen::Vector3d line_segment_end, Eigen::Vector3d& mesh_closest_point)
{
  Eigen::Vector3d shortest_dist(BIG_DOUBLE,BIG_DOUBLE,BIG_DOUBLE);

  //line intersection with all of the edges
  Eigen::Vector3d normal = ((points[1]-points[0]).cross(points[2]-points[1])).normalized();
  float d = points[1].dot(normal);
  Eigen::Vector3d p = line_segment_start - (line_segment_start.dot(normal) -d)*normal;
  Eigen::Vector3d r = (line_segment_end - (line_segment_end.dot(normal)-d)*normal) - p;

  for (int i = 0; i < 3; ++i)
  {
    Eigen::Vector3d q = points[i];
    Eigen::Vector3d s = points[(i+1)%3] - q;

    double u = ((q-p).cross(r)).norm()/(r.cross(s)).norm();
    double t = ((q-p).cross(s)).norm()/(r.cross(s)).norm();

    if (u > -EPISILON && u < 1+ EPISILON && t > -EPISILON && t < 1+EPISILON)
    {
      Eigen::Vector3d closest_point = q + u*s;
      Eigen::Vector3d mesh_close_point = (line_segment_start*(1-t) + line_segment_end*t);
      Eigen::Vector3d short_distance = mesh_close_point - closest_point;

      if (short_distance.norm() < shortest_dist.norm())
      {
        shortest_dist = short_distance;
        mesh_closest_point = mesh_close_point;
      }
    }

  }
  return shortest_dist;
}
Ejemplo n.º 2
0
typename
Container::const_reference
shortest_levenshtein(
	Container const &_container,
	typename Container::const_reference _ref
)
{
	typedef typename
	Container::value_type
	string_type;

	typedef typename
	string_type::size_type
	size_type;

	typedef typename
	Container::const_iterator
	const_iterator;

	size_type shortest_dist(
		::fcppt::algorithm::levenshtein(
			*_container.begin(),
			_ref
		)
	);

	const_iterator shortest(
		_container.begin()
	);

	for(
		const_iterator it(
			boost::next(
				_container.begin()
			)
		);
		it != _container.end();
		++it
	)
	{
		size_type const new_shortest_dist(
			::fcppt::algorithm::levenshtein(
				*it,
				_ref
			)
		);

		if(
			new_shortest_dist < shortest_dist
		)
		{
			shortest = it;

			shortest_dist = new_shortest_dist;
		}
	}

	return *shortest;
}
Ejemplo n.º 3
0
typename
boost::range_reference<
	Range
>::type
shortest_levenshtein(
	Range &_range,
	Value const &_element
)
{
	typedef typename
	boost::range_value<
		Range
	>::type
	string_type;

	typedef typename
	string_type::size_type
	size_type;

	typedef typename
	boost::range_iterator<
		Range
	>::type
	iterator;

	size_type shortest_dist(
		::fcppt::algorithm::levenshtein(
			*boost::begin(
				_range),
			_element
		)
	);

	iterator shortest(
		boost::begin(
			_range)
	);

	for(
		iterator it(
			std::next(
				boost::begin(
					_range)
			)
		);
		it != boost::end(_range);
		++it
	)
	{
		size_type const new_shortest_dist(
			::fcppt::algorithm::levenshtein(
				*it,
				_element
			)
		);

		if(
			new_shortest_dist < shortest_dist
		)
		{
			shortest = it;

			shortest_dist = new_shortest_dist;
		}
	}

	return *shortest;
}