Fixed an issue with DirectedPoint tangents

This commit is contained in:
Marc Garcia Puig 2019-03-22 13:08:37 +01:00
parent f53d218e85
commit 120a62ad0b
3 changed files with 24 additions and 7 deletions

View File

@ -73,23 +73,29 @@ namespace road {
}
}
/// returns a pair containing first = width, second = tangent
/// Returns a pair containing first = width, second = tangent,
/// for an specific Lane given an s and a iterator over lanes
template <typename T>
static std::pair<float, float> ComputeTotalLaneWidth(
const T container, const float s, const LaneId lane_id) {
const T container,
const float s, const
LaneId lane_id) {
const bool negative_lane_id = lane_id < 0;
float dist = 0.0;
float tangent = 0.0;
auto dist = 0.0;
auto tangent = 0.0;
for (const auto &lane : container) {
const auto current_polynomial =
lane.second->template GetInfo<RoadInfoLaneWidth>(s)->GetPolynomial();
float current_dist = current_polynomial.Evaluate(s);
auto current_dist = current_polynomial.Evaluate(s);
auto current_tangent = current_polynomial.Tangent(s);
if (lane.first != lane_id) {
dist += negative_lane_id ? current_dist : - current_dist;
tangent += current_tangent;
} else if (lane.first == lane_id) {
current_dist *= 0.5;
current_tangent *= 0.5;
dist += negative_lane_id ? current_dist : - current_dist;
tangent = current_polynomial.Tangent(s);
tangent += current_tangent;
break;
}
}
@ -213,6 +219,9 @@ namespace road {
lane_tangent = computed_width.second;
}
// Unreal's Y axis hack
lane_tangent *= -1;
// get a directed point in s and apply the computed lateral offet
DirectedPoint dp = road->GetDirectedPointIn(waypoint.s);

View File

@ -176,11 +176,15 @@ namespace road {
const auto lane_offset = _info.GetInfo<element::RoadInfoLaneOffset>(clamped_s);
const float offset = lane_offset->GetPolynomial().Evaluate(clamped_s);
const float tangent = lane_offset->GetPolynomial().Tangent(clamped_s);
// Apply road's lane offset record
element::DirectedPoint p = geometry->GetGeometry().PosFromDist(clamped_s - geometry->GetDistance());
// Unreal's Y axis hack
// Unreal's Y axis hack (the minus on the offset)
p.ApplyLateralOffset(-offset);
p.tangent += tangent;
// Apply road's elevation record
const auto elevation_info = GetElevationOn(s);
p.location.z = elevation_info.Evaluate(s);
p.pitch = elevation_info.Tangent(s);

View File

@ -75,6 +75,10 @@ namespace road {
std::unordered_map<SignId, signal::SignalReference>* getSignalReferences();
/// Returns a directed point on the center of the road (lane 0),
/// with the corresponding laneOffset and elevation records applied,
/// on distance "s".
/// - @ param s distance regarding the road to compute the point
element::DirectedPoint GetDirectedPointIn (const float s) const;
/// Returns a pair containing: