Antkeeper  0.0.1
trajectory.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_PHYSICS_ORBIT_TRAJECTORY_HPP
21 #define ANTKEEPER_PHYSICS_ORBIT_TRAJECTORY_HPP
22 
24 #include <engine/math/vector.hpp>
25 #include <vector>
26 
27 namespace physics {
28 namespace orbit {
29 
35 template <class T>
36 struct trajectory
37 {
39  T t0;
40 
42  T t1;
43 
45  T dt;
46 
48  std::size_t n;
49 
51  std::vector<T> a;
52 
59  [[nodiscard]] math::vec3<T> position(T t) const;
60 };
61 
62 template <class T>
64 {
65  t -= t0;
66  std::size_t i = static_cast<std::size_t>(t / dt);
67 
68  const T* ax = &a[i * n * 3];
69  const T* ay = ax + n;
70  const T* az = ay + n;
71 
72  t = (t / dt - i) * T(2) - T(1);
73 
74  math::vec3<T> r;
75  r.x() = math::polynomial::chebyshev::evaluate(ax, ay, t);
76  r.y() = math::polynomial::chebyshev::evaluate(ay, az, t);
77  r.z() = math::polynomial::chebyshev::evaluate(az, az + n, t);
78 
79  return r;
80 }
81 
82 } // namespace orbit
83 } // namespace physics
84 
85 #endif // ANTKEEPER_PHYSICS_ORBIT_TRAJECTORY_HPP
T evaluate(InputIt first, InputIt last, T x)
Evaluates a Chebyshev polynomial.
Definition: polynomial.hpp:66
Physics.
Definition: constants.hpp:23
n-dimensional vector.
Definition: vector.hpp:44
Describes the trajectory of an orbit with Chebyshev polynomials.
Definition: trajectory.hpp:37
math::vec3< T > position(T t) const
Calculates the Cartesian position of a trajectory at a given time.
Definition: trajectory.hpp:63
T t0
Start time of the trajectory.
Definition: trajectory.hpp:39
T dt
Time step duration.
Definition: trajectory.hpp:45
std::vector< T > a
Chebyshev polynomial coefficients.
Definition: trajectory.hpp:51
T t1
End time of the trajectory.
Definition: trajectory.hpp:42
std::size_t n
Chebyshev polynomial degree.
Definition: trajectory.hpp:48