LinearAlgebra
Loading...
Searching...
No Matches
Spherical.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 SPHERICAL_H
6#define SPHERICAL_H
7
8#include "Direction.h"
9
10namespace Passer {
11namespace LinearAlgebra {
12
13struct Vector3;
14template <typename T> class PolarOf;
15
18template <typename T> class SphericalOf {
19public:
22 float distance;
25 // AngleOf<T> horizontal;
28 // AngleOf<T> vertical;
30
32 SphericalOf<T>(float distance, AngleOf<T> horizontal, AngleOf<T> vertical);
34
41 static SphericalOf<T> Degrees(float distance, float horizontal,
42 float vertical);
44 constexpr static auto Deg = Degrees;
51 static SphericalOf<T> Radians(float distance, float horizontal,
52 float vertical);
53 // Short-hand Rad alias for the Radians function
54 constexpr static auto Rad = Radians;
55
60
67 Vector3 ToVector3() const;
68
70 const static SphericalOf<T> zero;
72 const static SphericalOf<T> forward;
74 const static SphericalOf<T> back;
76 const static SphericalOf<T> right;
78 const static SphericalOf<T> left;
80 const static SphericalOf<T> up;
82 const static SphericalOf<T> down;
83
88
94
99 SphericalOf<T> operator-=(const SphericalOf<T> &v);
104 SphericalOf<T> operator+=(const SphericalOf<T> &v);
105
111 friend SphericalOf<T> operator*(const SphericalOf<T> &v, float f) {
112 return SphericalOf<T>(v.distance * f, v.direction);
113 }
114 friend SphericalOf<T> operator*(float f, const SphericalOf<T> &v) {
115 return SphericalOf<T>(f * v.distance, v.direction);
116 }
117 SphericalOf<T> operator*=(float f);
123 friend SphericalOf<T> operator/(const SphericalOf<T> &v, float f) {
124 return SphericalOf<T>(v.distance / f, v.direction);
125 }
126 friend SphericalOf<T> operator/(float f, const SphericalOf<T> &v) {
127 return SphericalOf<T>(f / v.distance, v.direction);
128 }
129 SphericalOf<T> operator/=(float f);
130
135 static float DistanceBetween(const SphericalOf<T> &v1,
136 const SphericalOf<T> &v2);
142 const SphericalOf<T> &v2);
149 const SphericalOf<T> &v2,
150 const SphericalOf<T> &axis);
151
164 AngleOf<T> angle);
170 AngleOf<T> angle);
171};
172
182
183} // namespace LinearAlgebra
184} // namespace Passer
185using namespace Passer::LinearAlgebra;
186
187#include "Polar.h"
188#include "Vector3.h"
189
190#endif
An angle in various representations.
Definition Angle.h:21
A polar vector using an angle in various representations.
Definition Polar.h:18
A spherical vector using angles in various representations.
Definition Spherical.h:18
static SphericalOf< T > RotateHorizontal(const SphericalOf< T > &v, AngleOf< T > angle)
Rotate a spherical vector horizontally.
Definition Spherical.cpp:279
static const SphericalOf< T > down
A normalized down-oriented vector.
Definition Spherical.h:82
static const SphericalOf< T > up
A normalized up-oriented vector.
Definition Spherical.h:80
static const SphericalOf< T > back
A normalized back-oriented vector.
Definition Spherical.h:74
SphericalOf< T > operator-() const
Negate the vector.
Definition Spherical.cpp:129
static const SphericalOf< T > forward
A normalized forward-oriented vector.
Definition Spherical.h:72
static SphericalOf< T > Degrees(float distance, float horizontal, float vertical)
Create spherical vector without using AngleOf type. All given angles are in degrees.
Definition Spherical.cpp:37
static SphericalOf< T > Rotate(const SphericalOf &v, AngleOf< T > horizontalAngle, AngleOf< T > verticalAngle)
Rotate a spherical vector.
Definition Spherical.cpp:270
static AngleOf< T > AngleBetween(const SphericalOf< T > &v1, const SphericalOf< T > &v2)
Calculate the unsigned angle between two spherical vectors.
Definition Spherical.cpp:239
static SphericalOf< T > Radians(float distance, float horizontal, float vertical)
Create sperical vector without using the AngleOf type. All given angles are in radians.
Definition Spherical.cpp:46
static SphericalOf< T > FromPolar(PolarOf< T > v)
Create a Spherical coordinate from a Polar coordinate.
Definition Spherical.cpp:53
DirectionOf< T > direction
The angle in the horizontal plane in degrees, clockwise rotation.
Definition Spherical.h:29
Vector3 ToVector3() const
Convert the spherical coordinate to a Vector3 coordinate.
Definition Spherical.cpp:84
friend SphericalOf< T > operator*(const SphericalOf< T > &v, float f)
Scale the vector uniformly up.
Definition Spherical.h:111
static SphericalOf< T > FromVector3(Vector3 v)
Create a Spherical coordinate from a Vector3 coordinate.
Definition Spherical.cpp:60
SphericalOf< T > operator+(const SphericalOf< T > &v) const
Add a spherical vector to this vector.
Definition Spherical.cpp:152
float distance
The distance in meters.
Definition Spherical.h:22
static const SphericalOf< T > zero
A spherical vector with zero degree angles and distance.
Definition Spherical.h:70
friend SphericalOf< T > operator/(const SphericalOf< T > &v, float f)
Scale the vector uniformly down.
Definition Spherical.h:123
static float DistanceBetween(const SphericalOf< T > &v1, const SphericalOf< T > &v2)
Calculate the distance between two spherical coordinates.
Definition Spherical.cpp:228
static AngleOf< T > SignedAngleBetween(const SphericalOf< T > &v1, const SphericalOf< T > &v2, const SphericalOf< T > &axis)
Calculate the signed angle between two spherical vectors.
Definition Spherical.cpp:259
static SphericalOf< T > RotateVertical(const SphericalOf< T > &v, AngleOf< T > angle)
Rotate a spherical vector vertically.
Definition Spherical.cpp:286
static const SphericalOf< T > right
A normalized right-oriented vector.
Definition Spherical.h:76
SphericalOf< T > operator-(const SphericalOf< T > &v) const
Subtract a spherical vector from this vector.
SphericalOf< T > WithDistance(float distance)
Update the distance component of the spherical coordinate.
Definition Spherical.cpp:124
static const SphericalOf< T > left
A normalized left-oriented vector.
Definition Spherical.h:78
static constexpr auto Deg
Short-hand Deg alias for the Degrees function.
Definition Spherical.h:44
A 3-dimensional vector.
Definition Vector3.h:42