29constexpr float kKmhPerMs = 3.6f;
33constexpr float kNormEps = std::numeric_limits<float>::epsilon();
41 const auto vel = actor->GetVelocity();
42 return kKmhPerMs * std::sqrt(vel.x * vel.x + vel.y * vel.y + vel.z * vel.z);
51 const float rotated_x =
52 std::cos(radians) *
point.
x - std::sin(radians) *
point.y;
53 const float rotated_y =
54 std::sin(radians) *
point.x - std::cos(radians) *
point.y;
82 std::optional<std::pair<float, float>> angle_interval) {
85 const float norm_target = std::sqrt(dx * dx + dy * dy);
88 if (norm_target < 0.001f) {
91 if (norm_target > max_distance) {
94 if (!angle_interval.has_value()) {
98 const float min_angle = angle_interval->first;
99 const float max_angle = angle_interval->second;
102 const float dot = (fwd.x * dx + fwd.y * dy) / norm_target;
103 const float clamped = std::clamp(dot, -1.0f, 1.0f);
106 return min_angle < angle_deg && angle_deg < max_angle;
112 float orientation_deg) {
113 const float dx = target.
x - current.
x;
114 const float dy = target.
y - current.
y;
115 const float norm_target = std::sqrt(dx * dx + dy * dy);
118 const float fwd_x = std::cos(orientation_rad);
119 const float fwd_y = std::sin(orientation_rad);
122 const float denom = norm_target > 0.0f ? norm_target : kNormEps;
123 const float dot = (fwd_x * dx + fwd_y * dy) / denom;
124 const float clamped = std::clamp(dot, -1.0f, 1.0f);
127 return {norm_target, angle_deg};
133 const auto &wp_loc = waypoint->GetTransform().location;
134 const float dx = wp_loc.x - vehicle_transform.
location.
x;
135 const float dy = wp_loc.y - vehicle_transform.
location.
y;
136 return std::sqrt(dx * dx + dy * dy);
142 const float x = b.
x - a.
x;
143 const float y = b.
y - a.
y;
144 const float z = b.
z - a.
z;
146 const float norm = std::sqrt(
x *
x +
y *
y +
z *
z) + kNormEps;
147 return {
x / norm,
y / norm,
z / norm};
153 const float x = b.
x - a.
x;
154 const float y = b.
y - a.
y;
155 const float z = b.
z - a.
z;
156 return std::sqrt(
x *
x +
y *
y +
z *
z) + kNormEps;
166 auto debug = world->MakeDebugHelper();
167 for (
const auto &wpt : waypoints) {
169 const auto wpt_t = wpt->GetTransform();
173 wpt_t.location.z +
z);
176 begin.
x + std::cos(angle),
177 begin.
y + std::sin(angle),
Location location
Center of the BoundingBox in local space.
Vector3D extent
Half the size of the BoundingBox in local space.
static constexpr T ToRadians(T deg)
static constexpr T ToDegrees(T rad)
bool IsWithinDistance(const geom::Transform &target, const geom::Transform &reference, float max_distance, std::optional< std::pair< float, float > > angle_interval)
Returns true when target is within max_distance of reference.
float ComputeDistance(const geom::Location &a, const geom::Location &b)
Euclidean distance between two locations (matches numpy's regularised version that adds an epsilon to...
void DrawWaypoints(SharedPtr< client::World > world, const std::vector< SharedPtr< client::Waypoint > > &waypoints, float z)
Draw the supplied waypoints in the world for a fixed lifetime.
geom::Location GetTrafficLightTriggerLocation(SharedPtr< client::TrafficLight > traffic_light)
Compute the world-space trigger location of a traffic light, mirroring the helper in agents....
float GetSpeed(SharedPtr< client::Actor > actor)
Compute speed of an actor in km/h.
std::pair< float, float > ComputeMagnitudeAngle(const geom::Location &target, const geom::Location ¤t, float orientation_deg)
Returns the (distance, angle in degrees) from current to target relative to a forward orientation ori...
float DistanceVehicle(SharedPtr< client::Waypoint > waypoint, const geom::Transform &vehicle_transform)
2-D distance between a waypoint and a vehicle transform.
std::array< float, 3 > UnitVector(const geom::Location &a, const geom::Location &b)
Unit vector going from a to b, including the z component.
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr