From 7c1bc2ff6bd1a46f3587234928e8bffc76102294 Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Thu, 20 May 2021 00:19:52 +0800 Subject: [PATCH] Add physics::time namespace, add function to calculate ERA from UT1 --- src/ecs/systems/astronomy-system.cpp | 3 +- src/physics/physics.hpp | 1 + src/physics/time/time.hpp | 32 +++++++++++++++++ src/physics/time/ut1.hpp | 51 ++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/physics/time/time.hpp create mode 100644 src/physics/time/ut1.hpp diff --git a/src/ecs/systems/astronomy-system.cpp b/src/ecs/systems/astronomy-system.cpp index 3dd6d23..9614e39 100644 --- a/src/ecs/systems/astronomy-system.cpp +++ b/src/ecs/systems/astronomy-system.cpp @@ -24,6 +24,7 @@ #include "renderer/passes/sky-pass.hpp" #include "color/color.hpp" #include "physics/orbit/orbit.hpp" +#include "physics/time/ut1.hpp" #include "geom/cartesian.hpp" #include @@ -122,7 +123,7 @@ void astronomy_system::update(double t, double dt) const double earth_axial_tilt = math::radians(23.45); - const double earth_axial_rotation = math::two_pi * (0.7790572732640 + 1.00273781191135448 * universal_time); + const double earth_axial_rotation = physics::time::ut1::era(universal_time); const double earth_radius_au = 4.2635e-5; const double observer_altitude = earth_radius_au; diff --git a/src/physics/physics.hpp b/src/physics/physics.hpp index 4f04a13..bf71126 100644 --- a/src/physics/physics.hpp +++ b/src/physics/physics.hpp @@ -25,5 +25,6 @@ namespace physics {} #include "frame.hpp" #include "orbit/orbit.hpp" +#include "time/time.hpp" #endif // ANTKEEPER_PHYSICS_HPP diff --git a/src/physics/time/time.hpp b/src/physics/time/time.hpp new file mode 100644 index 0000000..8f96d7e --- /dev/null +++ b/src/physics/time/time.hpp @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_PHYSICS_TIME_HPP +#define ANTKEEPER_PHYSICS_TIME_HPP + +namespace physics { + +/// Time-related functions. +namespace time {} + +#include "ut1.hpp" + +} // namespace physics + +#endif // ANTKEEPER_PHYSICS_TIME_HPP diff --git a/src/physics/time/ut1.hpp b/src/physics/time/ut1.hpp new file mode 100644 index 0000000..e91560d --- /dev/null +++ b/src/physics/time/ut1.hpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_PHYSICS_TIME_UT1_HPP +#define ANTKEEPER_PHYSICS_TIME_UT1_HPP + +#include "math/constants.hpp" + +namespace physics { +namespace time { + +/// Functions which operate on UT1 universal time. +namespace ut1 { + +/** + * Calculates the Earth Rotation Angle (ERA) at a given UT1 date. + * + * @param t J2000 UT1 date. + * @return ERA at the given date, in radians. + */ +template +T era(T t); + +template +T era(T t) +{ + return math::two_pi * (T(0.7790572732640) + T(1.00273781191135448) * t); +} + +} // namespace ut1 + +} // namespace time +} // namespace physics + +#endif // ANTKEEPER_PHYSICS_TIME_UT1_HPP