Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
vector.hpp
Go to the documentation of this file.
1/*****************************************************************************/
2/********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/
3/*****************************************************************************/
4
5/*
6 * Copyright (c) 2022-2023 Advanced Robotics at the University of Washington <robomstr@uw.edu>
7 *
8 * This file is part of Taproot.
9 *
10 * Taproot is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Taproot is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Taproot. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef TAPROOT_VECTOR_HPP_
25#define TAPROOT_VECTOR_HPP_
26
28
30{
31// forward declare position to avoid circular dependency
32class Position;
33
34class Vector
35{
36public:
37 Vector(float x, float y, float z) : coordinates_({x, y, z}) {}
38
39 Vector(const Vector&& other) : coordinates_(std::move(other.coordinates_)) {}
40
41 Vector(const Vector& other) : coordinates_(CMSISMat(other.coordinates_)) {}
42
47
48 Vector(CMSISMat<3, 1>&& coordinates) : coordinates_(std::move(coordinates)) {}
49
50 inline float x() const { return coordinates_.data[0]; }
51
52 inline float y() const { return coordinates_.data[1]; }
53
54 inline float z() const { return coordinates_.data[2]; }
55
56 inline Vector& operator=(const Vector& other)
57 {
58 this->coordinates_ = other.coordinates_;
59 return *this;
60 }
61
62 inline Vector operator+(const Position& other) const;
63
64 inline Vector operator+(const Vector& other) const
65 {
66 return Vector(this->coordinates_ + other.coordinates_);
67 }
68
69 inline Vector operator-(const Vector& other) const
70 {
71 return Vector(this->coordinates_ - other.coordinates_);
72 }
73
74 inline Vector operator*(const float scale) const { return Vector(this->coordinates_ * scale); }
75
76 inline static float dot(const Vector& a, const Vector& b)
77 {
78 return a.x() * b.x() + a.y() * b.y() + a.z() * b.z();
79 }
80
81 inline float dot(const Vector& other) const { return dot(*this, other); }
82
83 inline Vector operator/(const float scale) const { return Vector(this->coordinates_ / scale); }
84
85 const inline CMSISMat<3, 1>& coordinates() const { return coordinates_; }
86
87 inline float magnitude() const { return sqrt(dot(*this, *this)); }
88
89 friend class Transform;
90 friend class DynamicPosition;
91
92private:
93 CMSISMat<3, 1> coordinates_;
94}; // class Vector
95} // namespace tap::algorithms::transforms
96
97#endif // TAPROOT_VECTOR_HPP_
Definition dynamic_position.hpp:35
Definition position.hpp:35
Definition transform.hpp:60
Definition vector.hpp:35
float y() const
Definition vector.hpp:52
Vector(CMSISMat< 3, 1 > &&coordinates)
Definition vector.hpp:48
float x() const
Definition vector.hpp:50
const CMSISMat< 3, 1 > & coordinates() const
Definition vector.hpp:85
float magnitude() const
Definition vector.hpp:87
Vector operator*(const float scale) const
Definition vector.hpp:74
static float dot(const Vector &a, const Vector &b)
Definition vector.hpp:76
Vector operator-(const Vector &other) const
Definition vector.hpp:69
Vector(float x, float y, float z)
Definition vector.hpp:37
Vector(const Vector &other)
Definition vector.hpp:41
Vector & operator=(const Vector &other)
Definition vector.hpp:56
Vector operator+(const Vector &other) const
Definition vector.hpp:64
Vector(const CMSISMat< 3, 1 > &coordinates)
Definition vector.hpp:46
Vector operator/(const float scale) const
Definition vector.hpp:83
Vector operator+(const Position &other) const
Definition vector.cpp:30
float dot(const Vector &other) const
Definition vector.hpp:81
float z() const
Definition vector.hpp:54
Vector(const Vector &&other)
Definition vector.hpp:39
Definition angular_velocity.hpp:30
Definition cmsis_mat.hpp:45
std::array< float, ROWS *COLS > data
Definition cmsis_mat.hpp:46