File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
nav2_util/include/nav2_util Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -282,6 +282,35 @@ inline double distance_to_segment(
282
282
return std::hypot (dx_proj, dy_proj);
283
283
}
284
284
285
+ /* *
286
+ * @brief Computes the 2D cross product between the vector from start to end and the vector from start to point.
287
+ * The sign of this calculation's result can be used to determine which side are you on of the track.
288
+ *
289
+ * See: https://en.wikipedia.org/wiki/Cross_product
290
+ *
291
+ * @param point The point to check relative to the segment.
292
+ * @param start The starting pose of the segment.
293
+ * @param end The ending pose of the segment.
294
+ * @return The signed 2D cross product value.
295
+ */
296
+ inline double cross_product_2d (
297
+ const geometry_msgs::msg::Point & point,
298
+ const geometry_msgs::msg::Pose & start,
299
+ const geometry_msgs::msg::Pose & end)
300
+ {
301
+ const auto & p = point;
302
+ const auto & a = start.position ;
303
+ const auto & b = end.position ;
304
+
305
+ const double path_vec_x = b.x - a.x ;
306
+ const double path_vec_y = b.y - a.y ;
307
+
308
+ const double robot_vec_x = p.x - a.x ;
309
+ const double robot_vec_y = p.y - a.y ;
310
+
311
+ return (path_vec_x * robot_vec_y) - (path_vec_y * robot_vec_x);
312
+ }
313
+
285
314
} // namespace geometry_utils
286
315
} // namespace nav2_util
287
316
You can’t perform that action at this time.
0 commit comments