Skip to content

Commit

Permalink
wip commit
Browse files Browse the repository at this point in the history
  • Loading branch information
darioizzo committed Sep 20, 2023
1 parent 7ce3441 commit 936a158
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions include/kep3/planets/keplerian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class kep3_DLL_PUBLIC keplerian {
double m_mu_self;
double m_radius;
double m_safe_radius;
double m_period;
bool m_ellipse;

friend class boost::serialization::access;
Expand All @@ -43,6 +44,7 @@ class kep3_DLL_PUBLIC keplerian {
ar &m_mu_self;
ar &m_radius;
ar &m_safe_radius;
ar &m_period;
ar &m_ellipse;
}

Expand All @@ -68,6 +70,7 @@ class kep3_DLL_PUBLIC keplerian {
[[nodiscard]] double get_radius() const;
[[nodiscard]] double get_safe_radius() const;
[[nodiscard]] std::string get_extra_info() const;
[[nodiscard]] double period(const kep3::epoch & = kep3::epoch()) const;

// Other methods
[[nodiscard]] kep3::epoch get_ref_epoch() const;
Expand Down
12 changes: 10 additions & 2 deletions src/planets/keplerian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ keplerian::keplerian(const epoch &ref_epoch,
std::array<double, 3> added_params)
: m_ref_epoch(ref_epoch), m_pos_vel_0(pos_vel), m_name(std::move(name)),
m_mu_central_body(mu_central_body), m_mu_self(added_params[0]),
m_radius(added_params[1]), m_safe_radius(added_params[2]), m_ellipse() {
m_radius(added_params[1]), m_safe_radius(added_params[2]), m_period(),
m_ellipse() {
double R =
std::sqrt(pos_vel[0][0] * pos_vel[0][0] + pos_vel[0][1] * pos_vel[0][1] +
pos_vel[0][2] * pos_vel[0][2]);
Expand All @@ -39,14 +40,17 @@ keplerian::keplerian(const epoch &ref_epoch,
2. -
mu_central_body / R;
(en > 0) ? m_ellipse = false : m_ellipse = true;
double a = -m_mu_central_body / 2. / en;
m_period = kep3::pi * 2. * std::sqrt(a * a * a / m_mu_central_body);
}

keplerian::keplerian(const epoch &ref_epoch, const std::array<double, 6> &par,
double mu_central_body, std::string name,
std::array<double, 3> added_params)
: m_ref_epoch(ref_epoch), m_pos_vel_0(), m_name(std::move(name)),
m_mu_central_body(mu_central_body), m_mu_self(added_params[0]),
m_radius(added_params[1]), m_safe_radius(added_params[2]), m_ellipse() {
m_radius(added_params[1]), m_safe_radius(added_params[2]), m_period(),
m_ellipse() {

if (par[0] * (1 - par[1]) <= 0) {
throw std::domain_error(
Expand All @@ -56,6 +60,8 @@ keplerian::keplerian(const epoch &ref_epoch, const std::array<double, 6> &par,
}
m_pos_vel_0 = kep3::par2ic(par, mu_central_body);
(par[0] < 0) ? m_ellipse = false : m_ellipse = true;
m_period =
kep3::pi * 2. * std::sqrt(par[0] * par[0] * par[0] / m_mu_central_body);
}

std::array<std::array<double, 3>, 2>
Expand All @@ -78,6 +84,8 @@ double keplerian::get_radius() const { return m_radius; }

double keplerian::get_safe_radius() const { return m_safe_radius; }

double keplerian::period(const kep3::epoch &) const { return m_period; }

kep3::epoch keplerian::get_ref_epoch() const { return m_ref_epoch; }

std::array<double, 6> keplerian::elements(kep3::elements_type el_type) const {
Expand Down

0 comments on commit 936a158

Please sign in to comment.