Repository navigation
Expand file tree
/
Copy pathCartesianFloat.h
More file actions
89 lines (74 loc) · 1.96 KB
/
Copy pathCartesianFloat.h
File metadata and controls
89 lines (74 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#include "vessl/vessl.h"
/**
* A structure defining a floating point Cartesian coordinate.
*/
struct CartesianFloat
{
float x, y, z;
constexpr CartesianFloat() : x(0), y(0), z(0) {}
constexpr CartesianFloat(const CartesianFloat&) = default;
constexpr CartesianFloat(float x, float y, float z) : x(x), y(y), z(z) {}
constexpr CartesianFloat(CartesianFloat&&) = default;
~CartesianFloat() = default;
vessl::matrix<float> toMatrix() { return vessl::matrix<float>(&x, 3, 1); }
[[nodiscard]] float getMagnitude() const
{
return vessl::math::sqrt(x*x + y*y + z*z);
}
[[nodiscard]] float getMagnitudeSquared() const
{
return x*x + y*y + z*z;
}
void setSpherical(float radius, float inclination, float azimuth)
{
x = radius * vessl::math::cos(azimuth) * vessl::math::sin(inclination);
y = radius * vessl::math::sin(azimuth) * vessl::math::sin(inclination);
z = radius * vessl::math::cos(inclination);
}
CartesianFloat& operator=(const CartesianFloat& other) = default;
CartesianFloat& operator=(CartesianFloat&& other) = default;
CartesianFloat& operator+=(const CartesianFloat& other)
{
x += other.x;
y += other.y;
z += other.z;
return *this;
}
friend CartesianFloat operator+(CartesianFloat lhs, const CartesianFloat& rhs)
{
lhs += rhs;
return lhs;
}
CartesianFloat& operator-=(const CartesianFloat& other)
{
x -= other.x;
y -= other.y;
z -= other.z;
return *this;
}
friend CartesianFloat operator-(CartesianFloat lhs, const CartesianFloat& rhs)
{
lhs -= rhs;
return lhs;
}
CartesianFloat& operator*=(const float& scalar)
{
x *= scalar;
y *= scalar;
z *= scalar;
return *this;
}
friend CartesianFloat operator*(CartesianFloat lhs, const float& rhs)
{
lhs *= rhs;
return lhs;
}
CartesianFloat& operator/=(const float& scalar)
{
x /= scalar;
y /= scalar;
z /= scalar;
return *this;
}
};