RoboidControl
Loading...
Searching...
No Matches
Polar.h
Go to the documentation of this file.
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0.If a copy of the MPL was not distributed with this
3// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
4
5#ifndef POLAR_H
6#define POLAR_H
7
8#include "Angle.h"
9
10namespace Passer {
11namespace LinearAlgebra {
12
13struct Vector2;
14struct Spherical;
15
19struct Polar {
20public:
23 float distance;
27
30 Polar();
36 Polar(float distance, Angle angle);
40 Polar(Vector2 v);
45
47 const static Polar zero;
49 const static Polar forward;
51 const static Polar back;
53 const static Polar right;
55 const static Polar left;
56
62 bool operator==(const Polar &v) const;
63
67 inline static float Magnitude(const Polar &v) { return v.distance; }
70 inline float magnitude() const { return this->distance; }
71
75 static Polar Normalize(const Polar &v);
78 Polar normalized() const;
79
83 Polar operator-() const;
84
88 Polar operator-(const Polar &v) const;
89 Polar operator-=(const Polar &v);
93 Polar operator+(const Polar &v) const;
94 Polar operator+=(const Polar &v);
95
101 friend Polar operator*(const Polar &v, float f);
102 friend Polar operator*(float f, const Polar &v);
103 Polar operator*=(float f);
109 friend Polar operator/(const Polar &v, float f);
110 friend Polar operator/(float f, const Polar &v);
111 Polar operator/=(float f);
112
117 static float Distance(const Polar &v1, const Polar &v2);
118
123 static Polar Rotate(const Polar &v, Angle a);
124};
125} // namespace LinearAlgebra
126} // namespace Passer
127using namespace Passer::LinearAlgebra;
128
129#include "Spherical.h"
130#include "Vector2.h"
131
132#endif
Definition Angle.h:9
Definition AbsoluteEncoder.h:5
A polar vector.
Definition Polar.h:19
static const Polar forward
A normalized forward-oriented vector.
Definition Polar.h:49
Angle angle
The angle in degrees clockwise rotation.
Definition Polar.h:26
static const Polar left
A normalized left-oriented vector.
Definition Polar.h:55
static Polar Rotate(const Polar &v, Angle a)
Rotate a vector.
Definition Polar.cpp:124
static const Polar back
A normalized back-oriented vector.
Definition Polar.h:51
Polar operator/=(float f)
Definition Polar.cpp:113
friend Polar operator/(const Polar &v, float f)
Scale the vector uniformly down.
Polar(Spherical s)
Convert a vector from spherical coordinates to polar coordinates.
static Polar Normalize(const Polar &v)
Convert the vector to a length of 1.
Definition Polar.cpp:44
Polar operator-=(const Polar &v)
Definition Polar.cpp:62
friend Polar operator/(float f, const Polar &v)
friend Polar operator*(const Polar &v, float f)
Scale the vector uniformly up.
friend Polar operator*(float f, const Polar &v)
bool operator==(const Polar &v) const
Equality test to another vector.
Definition Polar.cpp:40
float magnitude() const
The vector length.
Definition Polar.h:70
Polar normalized() const
Convert the vector to a length of a.
Definition Polar.cpp:48
static const Polar zero
A polar vector with zero degrees and distance.
Definition Polar.h:47
float distance
The distance in meters.
Definition Polar.h:23
Polar operator+=(const Polar &v)
Definition Polar.cpp:92
static float Distance(const Polar &v1, const Polar &v2)
The distance between two vectors.
Definition Polar.cpp:118
Polar operator+(const Polar &v) const
Add a polar vector to this vector.
Definition Polar.cpp:66
static float Magnitude(const Polar &v)
The vector length.
Definition Polar.h:67
Polar operator-() const
Negate the vector.
Definition Polar.cpp:53
static const Polar right
A normalized right-oriented vector.
Definition Polar.h:53
Polar operator*=(float f)
Definition Polar.cpp:103
Polar()
A new vector with polar coordinates with zero degrees and distance.
Definition Polar.cpp:7
A spherical vector.
Definition Spherical.h:21
A 2=dimensional vector.
Definition Vector2.h:38