23 const float l = std::sqrt(l2);
27 const float dot_p_w =
Dot2D(p - v, w - v);
28 const float t =
Clamp(dot_p_w / l2);
29 const Vector3D projection = v + t * (w - v);
30 return std::make_pair(t * l,
Distance2D(projection, p));
43 start_pos.
y = -start_pos.
y;
45 curvature = -curvature;
51 if (curvature < 0.0f) {
53 start_pos.
y = -start_pos.
y;
55 curvature = -curvature;
61 const float radius = 1.0f / curvature;
62 const Vector3D circ_center(0.0f, radius, 0.0f);
66 if (rotated_p == circ_center) {
67 return std::make_pair(0.0f, radius);
72 const Vector3D intersection = ((rotated_p - circ_center).MakeUnitVector() * radius) + circ_center;
78 const float last_point_angle = length / radius;
80 constexpr
float pi_half = Pi<float>() / 2.0f;
84 float angle = std::atan2(intersection.
y - radius, intersection.
x) + pi_half;
87 angle += Pi<float>() * 2.0f;
92 if (angle <= last_point_angle) {
93 return std::make_pair(
102 radius * std::cos(last_point_angle - pi_half),
103 radius * std::sin(last_point_angle - pi_half) + circ_center.
y,
105 const float end_dist =
Distance2D(end_pos, rotated_p);
106 return (start_dist < end_dist) ?
107 std::make_pair(0.0f, start_dist) :
108 std::make_pair(length, end_dist);
112 const float s = std::sin(angle);
113 const float c = std::cos(angle);
114 return Vector3D(p.
x * c - p.
y * s, p.
x * s + p.
y * c, 0.0f);
122 return {cy * cp, sy * cp, sp};
133 cy * sp * sr - sy * cr,
134 sy * sp * sr + cy * cr,
146 -cy * sp * cr - sy * sr,
147 -sy * sp * cr + cy * sr,
152 std::vector<int> result;
154 for(
int i = a; i <= b; ++i) {
158 for(
int i = a; i >= b; --i) {
static auto Dot2D(const Vector3D &a, const Vector3D &b)
static Vector3D GetUpVector(const Rotation &rotation)
Compute the unit vector pointing towards the Y-axis of rotation.
static std::pair< float, float > DistanceSegmentToPoint(const Vector3D &p, const Vector3D &v, const Vector3D &w)
Returns a pair containing:
static Vector3D GetForwardVector(const Rotation &rotation)
Compute the unit vector pointing towards the X-axis of rotation.
static T Clamp(T a, T min=T(0), T max=T(1))
This file contains definitions of common data structures used in traffic manager. ...
static Vector3D GetRightVector(const Rotation &rotation)
Compute the unit vector pointing towards the Y-axis of rotation.
static std::pair< float, float > DistanceArcToPoint(Vector3D p, Vector3D start_pos, float length, float heading, float curvature)
Returns a pair containing:
#define DEBUG_ASSERT(predicate)
static auto DistanceSquared2D(const Vector3D &a, const Vector3D &b)
static auto Distance2D(const Vector3D &a, const Vector3D &b)
static constexpr T ToRadians(T deg)
static double GetVectorAngle(const Vector3D &a, const Vector3D &b)
Returns the angle between 2 vectors in radians.
static std::vector< int > GenerateRange(int a, int b)
static auto Dot(const Vector3D &a, const Vector3D &b)
static Vector3D RotatePointOnOrigin2D(Vector3D p, float angle)