Skip to content

Commit

Permalink
planning: add util method to convert data from world coirdinate to re…
Browse files Browse the repository at this point in the history
…lative coord
  • Loading branch information
jmtao authored and xiaoxq committed Feb 24, 2020
1 parent 7e2fc76 commit bdcefe7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/planning/common/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,15 @@ cc_library(
],
)

cc_library(
name = "math_util_lib",
hdrs = ["math_util.h"],
copts = [
"-DMODULE_NAME=\\\"planning\\\"",
],
deps = [
"//cyber/common:log",
"//modules/common/util:map_util",
],
)
cpplint()
44 changes: 44 additions & 0 deletions modules/planning/common/util/math_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/******************************************************************************
* Copyright 2020 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once

#include "modules/common/math/math_utils.h"

namespace apollo {
namespace planning {
namespace util {

// Helper function to convert world coordinates to relative coordinates
// around the obstacle of interest.
std::pair<double, double> WorldCoordToObjCoord(
std::pair<double, double> input_world_coord,
std::pair<double, double> obj_world_coord, double obj_world_angle) {
double x_diff = input_world_coord.first - obj_world_coord.first;
double y_diff = input_world_coord.second - obj_world_coord.second;
double rho = std::sqrt(x_diff * x_diff + y_diff * y_diff);
double theta = std::atan2(y_diff, x_diff) - obj_world_angle;

return std::make_pair(std::cos(theta) * rho, std::sin(theta) * rho);
}

double WorldAngleToObjAngle(double input_world_angle,
double obj_world_angle) {
return apollo::common::math::NormalizeAngle(input_world_angle - obj_world_angle);
}

} // namespace msf
} // namespace localization
} // namespace apollo

0 comments on commit bdcefe7

Please sign in to comment.