LinearAlgebra
Loading...
Searching...
No Matches
Polar.h
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;
14template <typename T> class SphericalOf;
15
18template <typename T> class PolarOf {
19public:
22 float distance;
26
29 PolarOf();
36
42 static PolarOf<T> Degrees(float distance, float degrees);
44 constexpr static auto Deg = Degrees;
50 static PolarOf<T> Radians(float distance, float radians);
52 constexpr static auto Rad = Radians;
53
62
64 const static PolarOf zero;
66 const static PolarOf forward;
68 const static PolarOf back;
70 const static PolarOf right;
72 const static PolarOf left;
73
79 bool operator==(const PolarOf &v) const;
80
84 inline static float Magnitude(const PolarOf &v) { return v.distance; }
87 inline float magnitude() const { return this->distance; }
88
92 static PolarOf Normalize(const PolarOf &v);
95 PolarOf normalized() const;
96
100 PolarOf operator-() const;
101
105 PolarOf operator-(const PolarOf &v) const;
106 PolarOf operator-=(const PolarOf &v);
110 PolarOf operator+(const PolarOf &v) const;
111 PolarOf operator+=(const PolarOf &v);
112
118 friend PolarOf operator*(const PolarOf &v, float f) {
119 return PolarOf(v.distance * f, v.angle);
120 }
121 friend PolarOf operator*(float f, const PolarOf &v) {
122 return PolarOf(f * v.distance, v.angle);
123 }
124 PolarOf operator*=(float f);
130 friend PolarOf operator/(const PolarOf &v, float f) {
131 return PolarOf(v.distance / f, v.angle);
132 }
133 friend PolarOf operator/(float f, const PolarOf &v) {
134 return PolarOf(f / v.distance, v.angle);
135 }
136 PolarOf operator/=(float f);
137
142 static float Distance(const PolarOf &v1, const PolarOf &v2);
143
148 static PolarOf Rotate(const PolarOf &v, AngleOf<T> a);
149};
150
153// using Polar = PolarSingle;
154
155} // namespace LinearAlgebra
156} // namespace Passer
157using namespace Passer::LinearAlgebra;
158
159#include "Spherical.h"
160#include "Vector2.h"
161
162#endif
An angle in various representations.
Definition Angle.h:21
A polar vector using an angle in various representations.
Definition Polar.h:18
static PolarOf< T > FromSpherical(SphericalOf< T > v)
Convert a vector from spherical coordinates to polar coordinates.
Definition Polar.cpp:44
friend PolarOf operator*(const PolarOf &v, float f)
Scale the vector uniformly up.
Definition Polar.h:118
AngleOf< T > angle
The angle in degrees clockwise rotation.
Definition Polar.h:25
static const PolarOf zero
A polar vector with zero degrees and distance.
Definition Polar.h:64
static const PolarOf back
A normalized back-oriented vector.
Definition Polar.h:68
static PolarOf Normalize(const PolarOf &v)
Convert the vector to a length of 1.
Definition Polar.cpp:68
static constexpr auto Rad
Short-hand Rad alias for the Radians function.
Definition Polar.h:52
static PolarOf< T > Radians(float distance, float radians)
Create polar vector without using AngleOf type. All given angles are in radians.
Definition Polar.cpp:33
static const PolarOf right
A normalized right-oriented vector.
Definition Polar.h:70
float magnitude() const
The vector length.
Definition Polar.h:87
PolarOf operator+(const PolarOf &v) const
Add a polar vector to this vector.
Definition Polar.cpp:108
static const PolarOf forward
A normalized forward-oriented vector.
Definition Polar.h:66
static const PolarOf left
A normalized left-oriented vector.
Definition Polar.h:72
friend PolarOf operator/(const PolarOf &v, float f)
Scale the vector uniformly down.
Definition Polar.h:130
PolarOf()
A new vector with polar coordinates with zero degrees and distance.
Definition Polar.cpp:6
static PolarOf Rotate(const PolarOf &v, AngleOf< T > a)
Rotate a vector.
Definition Polar.cpp:158
static PolarOf< T > FromVector2(Vector2 v)
Convert a vector from 2D carthesian coordinates to polar coordinates.
Definition Polar.cpp:37
bool operator==(const PolarOf &v) const
Equality test to another vector.
Definition Polar.cpp:63
static constexpr auto Deg
Short-hand Deg alias for the Degrees function.
Definition Polar.h:44
float distance
The distance in meters.
Definition Polar.h:22
static float Distance(const PolarOf &v1, const PolarOf &v2)
The distance between two vectors.
Definition Polar.cpp:151
PolarOf operator-() const
Negate the vector.
Definition Polar.cpp:77
static PolarOf< T > Degrees(float distance, float degrees)
Create polar vector without using AngleOf type. All given angles are in degrees.
Definition Polar.cpp:26
static float Magnitude(const PolarOf &v)
The vector length.
Definition Polar.h:84
PolarOf normalized() const
Convert the vector to a length of a.
Definition Polar.cpp:72
A spherical vector using angles in various representations.
Definition Spherical.h:18
A 2-dimensional vector.
Definition Vector2.h:38