WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
CoordinateAxis.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <Eigen/Core>
8#include <gcem.hpp>
9#include <wpi/SymbolExports.h>
10
11#include "frc/geometry/Pose3d.h"
13
14namespace frc {
15
16/**
17 * A class representing a coordinate system axis within the NWU coordinate
18 * system.
19 */
21 public:
22 /**
23 * Constructs a coordinate system axis within the NWU coordinate system and
24 * normalizes it.
25 *
26 * @param x The x component.
27 * @param y The y component.
28 * @param z The z component.
29 */
30 constexpr CoordinateAxis(double x, double y, double z) {
31 double norm = gcem::hypot(x, y, z);
32 m_axis = Eigen::Vector3d{{x / norm, y / norm, z / norm}};
33 }
34
35 CoordinateAxis(const CoordinateAxis&) = default;
37
40
41 /**
42 * Returns a coordinate axis corresponding to +X in the NWU coordinate system.
43 */
44 static constexpr CoordinateAxis N() { return CoordinateAxis{1.0, 0.0, 0.0}; }
45
46 /**
47 * Returns a coordinate axis corresponding to -X in the NWU coordinate system.
48 */
49 static constexpr CoordinateAxis S() { return CoordinateAxis{-1.0, 0.0, 0.0}; }
50
51 /**
52 * Returns a coordinate axis corresponding to -Y in the NWU coordinate system.
53 */
54 static constexpr CoordinateAxis E() { return CoordinateAxis{0.0, -1.0, 0.0}; }
55
56 /**
57 * Returns a coordinate axis corresponding to +Y in the NWU coordinate system.
58 */
59 static constexpr CoordinateAxis W() { return CoordinateAxis{0.0, 1.0, 0.0}; }
60
61 /**
62 * Returns a coordinate axis corresponding to +Z in the NWU coordinate system.
63 */
64 static constexpr CoordinateAxis U() { return CoordinateAxis{0.0, 0.0, 1.0}; }
65
66 /**
67 * Returns a coordinate axis corresponding to -Z in the NWU coordinate system.
68 */
69 static constexpr CoordinateAxis D() { return CoordinateAxis{0.0, 0.0, -1.0}; }
70
71 private:
72 friend class CoordinateSystem;
73
74 Eigen::Vector3d m_axis;
75};
76
77} // namespace frc
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
A class representing a coordinate system axis within the NWU coordinate system.
Definition CoordinateAxis.h:20
static constexpr CoordinateAxis D()
Returns a coordinate axis corresponding to -Z in the NWU coordinate system.
Definition CoordinateAxis.h:69
static constexpr CoordinateAxis N()
Returns a coordinate axis corresponding to +X in the NWU coordinate system.
Definition CoordinateAxis.h:44
static constexpr CoordinateAxis S()
Returns a coordinate axis corresponding to -X in the NWU coordinate system.
Definition CoordinateAxis.h:49
CoordinateAxis(const CoordinateAxis &)=default
static constexpr CoordinateAxis U()
Returns a coordinate axis corresponding to +Z in the NWU coordinate system.
Definition CoordinateAxis.h:64
CoordinateAxis(CoordinateAxis &&)=default
CoordinateAxis & operator=(CoordinateAxis &&)=default
constexpr CoordinateAxis(double x, double y, double z)
Constructs a coordinate system axis within the NWU coordinate system and normalizes it.
Definition CoordinateAxis.h:30
static constexpr CoordinateAxis E()
Returns a coordinate axis corresponding to -Y in the NWU coordinate system.
Definition CoordinateAxis.h:54
static constexpr CoordinateAxis W()
Returns a coordinate axis corresponding to +Y in the NWU coordinate system.
Definition CoordinateAxis.h:59
CoordinateAxis & operator=(const CoordinateAxis &)=default
A helper class that converts Pose3d objects between different standard coordinate frames.
Definition CoordinateSystem.h:20
Definition CAN.h:11
constexpr common_return_t< T1, T2 > hypot(const T1 x, const T2 y) noexcept
Compile-time Pythagorean addition function.
Definition hypot.hpp:147