本文整理汇总了C++中eigen::Vector2f::normalized方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector2f::normalized方法的具体用法?C++ Vector2f::normalized怎么用?C++ Vector2f::normalized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eigen::Vector2f
的用法示例。
在下文中一共展示了Vector2f::normalized方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: point
/** Get edge closest to a specified point.
* The point must be within an imaginery line segment parallel to
* the edge, that is a line perpendicular to the edge must go
* through the point and a point on the edge line segment.
* @param pos_x X coordinate in global (map) frame of point
* @param pos_y X coordinate in global (map) frame of point
* @return edge closest to the given point, or invalid edge if
* such an edge does not exist.
*/
NavGraphEdge
NavGraph::closest_edge(float pos_x, float pos_y) const
{
float min_dist = std::numeric_limits<float>::max();
NavGraphEdge rv;
Eigen::Vector2f point(pos_x, pos_y);
for (const NavGraphEdge &edge : edges_) {
const Eigen::Vector2f origin(edge.from_node().x(), edge.from_node().y());
const Eigen::Vector2f target(edge.to_node().x(), edge.to_node().y());
const Eigen::Vector2f direction(target - origin);
const Eigen::Vector2f direction_norm = direction.normalized();
const Eigen::Vector2f diff = point - origin;
const float t = direction.dot(diff) / direction.squaredNorm();
if (t >= 0.0 && t <= 1.0) {
// projection of the point onto the edge is within the line segment
float distance = (diff - direction_norm.dot(diff) * direction_norm).norm();
if (distance < min_dist) {
min_dist = distance;
rv = edge;
}
}
}
return rv;
}
示例2: Exception
/** Get the point on edge closest to a given point.
* The method determines a line perpendicular to the edge which goes through
* the given point, i.e. the point must be within the imaginary line segment.
* Then the point on the edge which crosses with that perpendicular line
* is returned.
* @param x X coordinate of point to get point on edge for
* @param y Y coordinate of point to get point on edge for
* @return coordinate of point on edge closest to given point
* @throw Exception thrown if the point is out of the line segment and
* no line perpendicular to the edge going through the given point can
* be found.
*/
cart_coord_2d_t
NavGraphEdge::closest_point_on_edge(float x, float y) const
{
const Eigen::Vector2f point(x, y);
const Eigen::Vector2f origin(from_node_.x(), from_node_.y());
const Eigen::Vector2f target(to_node_.x(), to_node_.y());
const Eigen::Vector2f direction(target - origin);
const Eigen::Vector2f direction_norm = direction.normalized();
const Eigen::Vector2f diff = point - origin;
const float t = direction.dot(diff) / direction.squaredNorm();
if (t >= 0.0 && t <= 1.0) {
// projection of the point onto the edge is within the line segment
Eigen::Vector2f point_on_line = origin + direction_norm.dot(diff) * direction_norm;
return cart_coord_2d_t(point_on_line[0], point_on_line[1]);
}
throw Exception("Point (%f,%f) is not on edge %s--%s", x, y,
from_.c_str(), to_.c_str());
}