Add spherical/cartesian transforms
This commit is contained in:
parent
16d05e9ea6
commit
ea50f64857
22
vector.cpp
22
vector.cpp
@ -162,6 +162,28 @@ vector::normalised (void) const {
|
||||
}
|
||||
|
||||
|
||||
vector
|
||||
vector::spherical_to_cartesian (const vector &s) {
|
||||
return {
|
||||
s.x * sin (s.y) * cos (s.z),
|
||||
s.x * sin (s.y) * sin (s.z),
|
||||
s.x * cos (s.y),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
vector
|
||||
vector::cartesian_to_spherical (const vector &c) {
|
||||
double mag = c.magnitude ();
|
||||
|
||||
return {
|
||||
mag,
|
||||
acos (c.z / mag),
|
||||
atan2 (c.y, c.x)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
vector::sanity (void) const {
|
||||
check_soft (!std::isnan (x));
|
||||
|
@ -53,6 +53,9 @@ namespace util {
|
||||
vector& normalise (void);
|
||||
vector normalised (void) const;
|
||||
|
||||
static vector spherical_to_cartesian (const vector &);
|
||||
static vector cartesian_to_spherical (const vector &);
|
||||
|
||||
void sanity (void) const;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user