test_3d_embedding.cpp
Go to the documentation of this file.
1 // Copyright 2024 Ekumen, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <gtest/gtest.h>
16 #include <beluga/3d_embedding.hpp>
17 #include <sophus/se2.hpp>
18 #include <sophus/se3.hpp>
19 
20 using Sophus::SE2d;
21 using Sophus::SE3d;
22 using Sophus::SO2d;
23 using Sophus::SO3d;
24 namespace beluga {
25 
26 TEST(Embed3DTests, Se3ToSe2) {
27  {
28  const auto identity_2d = SE2d{};
29  const auto identity_3d = SE3d{};
30  ASSERT_TRUE(identity_2d.matrix().isApprox(To2d(identity_3d).matrix()));
31  }
32  {
33  const auto rotation_about_z_2d = SE2d::rot(0.5);
34  const auto rotation_about_z_3d = SE3d::rotZ(0.5);
35  ASSERT_TRUE(rotation_about_z_2d.matrix().isApprox(To2d(rotation_about_z_3d).matrix()));
36  }
37  {
38  const auto identity_2d = SE2d{};
39  const auto rotation_about_x_3d = SE3d::rotX(0.5);
40  ASSERT_TRUE(identity_2d.matrix().isApprox(To2d(rotation_about_x_3d).matrix()));
41  }
42  {
43  const auto identity_2d = SE2d{};
44  const auto rotation_about_y_3d = SE3d::rotY(0.5);
45  ASSERT_TRUE(identity_2d.matrix().isApprox(To2d(rotation_about_y_3d).matrix()));
46  }
47  {
48  const auto translation_3d = SE3d{Sophus::SO3d{}, Eigen::Vector3d{1, 2, 4}};
49  ASSERT_TRUE(To2d(translation_3d).translation().isApprox(Eigen::Vector2d{1, 2}));
50  }
51 }
52 
53 TEST(Embed3DTests, Se2ToSe3) {
54  {
55  const auto identity_3d = SE3d{};
56  const auto identity_2d = SE2d{};
57  ASSERT_TRUE(To3d(identity_2d).matrix().isApprox(identity_3d.matrix()));
58  }
59  {
60  const auto rotation_about_z_3d = SE3d::rotZ(0.5);
61  const auto rotation_about_z_2d = SE2d::rot(0.5);
62  ASSERT_TRUE(To3d(rotation_about_z_2d).matrix().isApprox(rotation_about_z_3d.matrix()));
63  }
64  {
65  const auto translation_2d = SE2d{0, Eigen::Vector2d{1, 2}};
66  ASSERT_TRUE(To3d(translation_2d).translation().isApprox(Eigen::Vector3d{1, 2, 0}));
67  }
68 }
69 
70 } // namespace beluga
Sophus::SE3::rotY
static SOPHUS_FUNC SE3 rotY(Scalar const &y)
beluga::To2d
Sophus::SE2d To2d(const Sophus::SE3d &tf)
Transforms a SE3 transform into a SE2 transform, by flattening the Z axis.
Definition: 3d_embedding.hpp:24
Sophus::SO3
beluga::To3d
Sophus::SE3d To3d(const Sophus::SE2d &tf)
Embed a SE2 transform into 3D space with zero Z translation and only rotation about the Z axis.
Definition: 3d_embedding.hpp:29
Sophus::SE3::rotZ
static SOPHUS_FUNC SE3 rotZ(Scalar const &z)
se2.hpp
3d_embedding.hpp
Sophus::SE2
Sophus::SE3
Sophus::SE2::rot
static SOPHUS_FUNC SE2 rot(Scalar const &x)
Sophus::SO3d
SO3< double > SO3d
Sophus::SE3d
SE3< double > SE3d
Sophus::SE2d
SE2< double > SE2d
Sophus::SO2d
SO2< double > SO2d
Sophus::SE3::rotX
static SOPHUS_FUNC SE3 rotX(Scalar const &x)
beluga
The main Beluga namespace.
Definition: 3d_embedding.hpp:21
beluga::TEST
TEST(Bresenham, MultiPassGuarantee)
Definition: test_bresenham.cpp:27
se3.hpp


beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53