mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
This is useful for undoing transformations. One application my FRC team found was converting perspective n-point data from a "camera to target" coordinate frame transformation to a "target to camera" coordinate frame transformation.
34 lines
1.4 KiB
C++
34 lines
1.4 KiB
C++
/*----------------------------------------------------------------------------*/
|
|
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
/* the project. */
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
#include <cmath>
|
|
|
|
#include "frc/geometry/Pose2d.h"
|
|
#include "frc/geometry/Rotation2d.h"
|
|
#include "frc/geometry/Transform2d.h"
|
|
#include "frc/geometry/Translation2d.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace frc;
|
|
|
|
static constexpr double kEpsilon = 1E-9;
|
|
|
|
TEST(Transform2dTest, Inverse) {
|
|
const Pose2d initial{1_m, 2_m, Rotation2d(45.0_deg)};
|
|
const Transform2d transform{Translation2d{5.0_m, 0.0_m}, Rotation2d(5.0_deg)};
|
|
|
|
auto transformed = initial + transform;
|
|
auto untransformed = transformed + transform.Inverse();
|
|
|
|
EXPECT_NEAR(initial.Translation().X().to<double>(),
|
|
untransformed.Translation().X().to<double>(), kEpsilon);
|
|
EXPECT_NEAR(initial.Translation().Y().to<double>(),
|
|
untransformed.Translation().Y().to<double>(), kEpsilon);
|
|
EXPECT_NEAR(initial.Rotation().Degrees().to<double>(),
|
|
untransformed.Rotation().Degrees().to<double>(), kEpsilon);
|
|
}
|