WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
CoordinateAxis.hpp
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
11
12namespace wpi::math {
13
14/**
15 * A class representing a coordinate system axis within the NWU coordinate
16 * system.
17 */
19 public:
20 /**
21 * Constructs a coordinate system axis within the NWU coordinate system and
22 * normalizes it.
23 *
24 * @param x The x component.
25 * @param y The y component.
26 * @param z The z component.
27 */
28 constexpr CoordinateAxis(double x, double y, double z) {
29 double norm = gcem::hypot(x, y, z);
30 m_axis = Eigen::Vector3d{{x / norm, y / norm, z / norm}};
31 }
32
33 CoordinateAxis(const CoordinateAxis&) = default;
35
38
39 /**
40 * Returns a coordinate axis corresponding to +X in the NWU coordinate system.
41 */
42 static constexpr CoordinateAxis N() { return CoordinateAxis{1.0, 0.0, 0.0}; }
43
44 /**
45 * Returns a coordinate axis corresponding to -X in the NWU coordinate system.
46 */
47 static constexpr CoordinateAxis S() { return CoordinateAxis{-1.0, 0.0, 0.0}; }
48
49 /**
50 * Returns a coordinate axis corresponding to -Y in the NWU coordinate system.
51 */
52 static constexpr CoordinateAxis E() { return CoordinateAxis{0.0, -1.0, 0.0}; }
53
54 /**
55 * Returns a coordinate axis corresponding to +Y in the NWU coordinate system.
56 */
57 static constexpr CoordinateAxis W() { return CoordinateAxis{0.0, 1.0, 0.0}; }
58
59 /**
60 * Returns a coordinate axis corresponding to +Z in the NWU coordinate system.
61 */
62 static constexpr CoordinateAxis U() { return CoordinateAxis{0.0, 0.0, 1.0}; }
63
64 /**
65 * Returns a coordinate axis corresponding to -Z in the NWU coordinate system.
66 */
67 static constexpr CoordinateAxis D() { return CoordinateAxis{0.0, 0.0, -1.0}; }
68
69 private:
70 friend class CoordinateSystem;
71
72 Eigen::Vector3d m_axis;
73};
74
75} // namespace wpi::math
#define WPILIB_DLLEXPORT
Definition SymbolExports.hpp:36
CoordinateAxis & operator=(const CoordinateAxis &)=default
CoordinateAxis & operator=(CoordinateAxis &&)=default
static constexpr CoordinateAxis S()
Returns a coordinate axis corresponding to -X in the NWU coordinate system.
Definition CoordinateAxis.hpp:47
static constexpr CoordinateAxis N()
Returns a coordinate axis corresponding to +X in the NWU coordinate system.
Definition CoordinateAxis.hpp:42
static constexpr CoordinateAxis D()
Returns a coordinate axis corresponding to -Z in the NWU coordinate system.
Definition CoordinateAxis.hpp:67
static constexpr CoordinateAxis W()
Returns a coordinate axis corresponding to +Y in the NWU coordinate system.
Definition CoordinateAxis.hpp:57
friend class CoordinateSystem
Definition CoordinateAxis.hpp:70
static constexpr CoordinateAxis U()
Returns a coordinate axis corresponding to +Z in the NWU coordinate system.
Definition CoordinateAxis.hpp:62
CoordinateAxis(const CoordinateAxis &)=default
CoordinateAxis(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.hpp:28
static constexpr CoordinateAxis E()
Returns a coordinate axis corresponding to -Y in the NWU coordinate system.
Definition CoordinateAxis.hpp:52
constexpr common_return_t< T1, T2 > hypot(const T1 x, const T2 y) noexcept
Compile-time Pythagorean addition function.
Definition hypot.hpp:147
Definition LinearSystem.hpp:20