CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
test
common
test_radar_polar_to_cartesian.cpp
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#include "
test.h
"
8
9
#include <
carla/ros2/publishers/RadarPolarToCartesian.h
>
10
11
#include <cmath>
12
13
namespace
{
14
constexpr
float
kEps = 1e-5f;
15
}
// namespace
16
17
TEST
(RadarPolarToCartesian, depth_zero_collapses_to_origin) {
18
const
auto
p =
carla::ros2::RadarPolarToCartesian
(0.0f, 0.0f, 0.0f);
19
EXPECT_NEAR(p[0], 0.0f, kEps);
20
EXPECT_NEAR(p[1], 0.0f, kEps);
21
EXPECT_NEAR(p[2], 0.0f, kEps);
22
}
23
24
TEST
(RadarPolarToCartesian, pure_depth_lands_on_x_axis) {
25
// azimuth = 0, altitude = 0: point is straight in front of the sensor along
26
// the positive x axis at distance depth.
27
const
auto
p =
carla::ros2::RadarPolarToCartesian
(10.0f, 0.0f, 0.0f);
28
EXPECT_NEAR(p[0], 10.0f, kEps);
29
EXPECT_NEAR(p[1], 0.0f, kEps);
30
EXPECT_NEAR(p[2], 0.0f, kEps);
31
}
32
33
TEST
(RadarPolarToCartesian, positive_azimuth_flips_y_to_negative) {
34
// azimuth = +pi/2 with the per-axis sign flip means y component picks up
35
// sin(-pi/2) * cos(0) = -1. depth = 10 -> y = -10.
36
constexpr
float
kHalfPi =
static_cast<
float
>
(M_PI) / 2.0f;
37
const
auto
p =
carla::ros2::RadarPolarToCartesian
(10.0f, kHalfPi, 0.0f);
38
EXPECT_NEAR(p[0], 0.0f, kEps);
39
EXPECT_NEAR(p[1], -10.0f, kEps);
40
EXPECT_NEAR(p[2], 0.0f, kEps);
41
}
42
43
TEST
(RadarPolarToCartesian, positive_altitude_lifts_z) {
44
// altitude = +pi/2, azimuth = 0: point straight up the +z axis.
45
constexpr
float
kHalfPi =
static_cast<
float
>
(M_PI) / 2.0f;
46
const
auto
p =
carla::ros2::RadarPolarToCartesian
(10.0f, 0.0f, kHalfPi);
47
EXPECT_NEAR(p[0], 0.0f, kEps);
48
EXPECT_NEAR(p[1], 0.0f, kEps);
49
EXPECT_NEAR(p[2], 10.0f, kEps);
50
}
51
52
TEST
(RadarPolarToCartesian, negative_azimuth_mirrors_y) {
53
// azimuth = -pi/2 -> y component picks up sin(pi/2) = +1.
54
constexpr
float
kHalfPi =
static_cast<
float
>
(M_PI) / 2.0f;
55
const
auto
p =
carla::ros2::RadarPolarToCartesian
(10.0f, -kHalfPi, 0.0f);
56
EXPECT_NEAR(p[0], 0.0f, kEps);
57
EXPECT_NEAR(p[1], 10.0f, kEps);
58
EXPECT_NEAR(p[2], 0.0f, kEps);
59
}
60
61
TEST
(RadarPolarToCartesian, combined_polar_matches_hand_computed) {
62
// depth = 2, azimuth = pi/4, altitude = pi/6.
63
constexpr
float
depth = 2.0f;
64
const
float
azimuth =
static_cast<
float
>
(M_PI) / 4.0f;
65
const
float
altitude =
static_cast<
float
>
(M_PI) / 6.0f;
66
const
auto
p =
carla::ros2::RadarPolarToCartesian
(depth, azimuth, altitude);
67
68
const
float
expected_x = depth * std::cos(azimuth) * std::cos(-altitude);
69
const
float
expected_y = depth * std::sin(-azimuth) * std::cos(altitude);
70
const
float
expected_z = depth * std::sin(altitude);
71
72
EXPECT_NEAR(p[0], expected_x, kEps);
73
EXPECT_NEAR(p[1], expected_y, kEps);
74
EXPECT_NEAR(p[2], expected_z, kEps);
75
}
RadarPolarToCartesian.h
carla::ros2::RadarPolarToCartesian
std::array< float, 3 > RadarPolarToCartesian(float depth, float azimuth, float altitude) noexcept
Definition
RadarPolarToCartesian.h:25
test.h
TEST
TEST(agents_types, road_option_values_match_python)
Definition
test_agents.cpp:40
Generated by
1.18.0