Skip to content

Commit

Permalink
fix(utils): improve monotonic bound generation logic autowarefoundati…
Browse files Browse the repository at this point in the history
…on#4706

Signed-off-by: kosuke55 <[email protected]>
  • Loading branch information
kosuke55 committed Aug 24, 2023
1 parent bd5b24c commit fcf8987
Show file tree
Hide file tree
Showing 3 changed files with 295 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,28 @@ inline bool isTwistCovarianceValid(
return false;
}

// NOTE: much faster than boost::geometry::intersects()
inline std::optional<geometry_msgs::msg::Point> intersect(
const geometry_msgs::msg::Point & p1, const geometry_msgs::msg::Point & p2,
const geometry_msgs::msg::Point & p3, const geometry_msgs::msg::Point & p4)
{
// calculate intersection point
const double det = (p1.x - p2.x) * (p4.y - p3.y) - (p4.x - p3.x) * (p1.y - p2.y);
if (det == 0.0) {
return std::nullopt;
}

const double t = ((p4.y - p3.y) * (p4.x - p2.x) + (p3.x - p4.x) * (p4.y - p2.y)) / det;
const double s = ((p2.y - p1.y) * (p4.x - p2.x) + (p1.x - p2.x) * (p4.y - p2.y)) / det;
if (t < 0 || 1 < t || s < 0 || 1 < s) {
return std::nullopt;
}

geometry_msgs::msg::Point intersect_point;
intersect_point.x = t * p1.x + (1.0 - t) * p2.x;
intersect_point.y = t * p1.y + (1.0 - t) * p2.y;
return intersect_point;
}
} // namespace tier4_autoware_utils

#endif // TIER4_AUTOWARE_UTILS__GEOMETRY__GEOMETRY_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,9 @@ DrivableAreaInfo combineDrivableAreaInfo(
void extractObstaclesFromDrivableArea(
PathWithLaneId & path, const std::vector<DrivableAreaInfo::Obstacle> & obstacles);

void makeBoundLongitudinallyMonotonic(PathWithLaneId & path, const bool is_bound_left);
void makeBoundLongitudinallyMonotonic(
PathWithLaneId & path, const std::shared_ptr<const PlannerData> & planner_data,
const bool is_bound_left);

std::optional<lanelet::Polygon3d> getPolygonByPoint(
const std::shared_ptr<RouteHandler> & route_handler, const lanelet::ConstPoint3d & point,
Expand Down
Loading

0 comments on commit fcf8987

Please sign in to comment.