FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
rotation_path.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2006-2008 Marc Brooker and Michael Inggs
4// Copyright (c) 2008-present FERS Contributors (see AUTHORS.md).
5//
6// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
7
8/**
9 * @file rotation_path.cpp
10 * @brief Implementation of the RotationPath class.
11 */
12
13#include "rotation_path.h"
14
15#include <algorithm>
16#include <cmath>
17
18#include "coord.h"
19#include "geometry_ops.h"
20#include "path_utils.h"
21
22namespace math
23{
24 void RotationPath::addCoord(const RotationCoord& coord) noexcept
25 {
26 const auto iter = std::lower_bound(_coords.begin(), _coords.end(), coord);
27 _coords.insert(iter, coord);
28 _final = false;
29 }
30
32 {
33 if (!_final)
34 {
35 throw PathException("Finalize not called before getPosition in RotationPath.");
36 }
37 RotationCoord coord{};
38
39 switch (_type)
40 {
42 getPositionStatic(coord, _coords);
43 break;
45 getPositionLinear(t, coord, _coords);
46 break;
48 getPositionCubic(t, coord, _coords, _dd);
49 break;
51 coord.azimuth = std::fmod(t * _rate.azimuth + _start.azimuth, 2 * PI);
52 coord.elevation = std::fmod(t * _rate.elevation + _start.elevation, 2 * PI);
53 break;
54 default:
55 throw PathException("Unknown interpolation type.");
56 }
57
58 return {1, coord.azimuth, coord.elevation};
59 }
60
62 {
63 if (!_final)
64 {
65 if (_type == InterpType::INTERP_CUBIC)
66 {
67 finalizeCubic(_coords, _dd);
68 }
69 _final = true;
70 }
71 }
72
73 void RotationPath::setInterp(const InterpType setinterp) noexcept
74 {
75 _type = setinterp;
76 _final = false;
77 }
78
79 void RotationPath::setConstantRate(const RotationCoord& setstart, const RotationCoord& setrate) noexcept
80 {
81 _start = setstart;
82 _rate = setrate;
83 _type = InterpType::INTERP_CONSTANT;
84 _final = true;
85 }
86}
Exception class for handling path-related errors.
Definition path_utils.h:27
void finalize()
Finalizes the rotation path for interpolation.
void setConstantRate(const RotationCoord &setstart, const RotationCoord &setrate) noexcept
Sets constant rate interpolation.
void setInterp(InterpType setinterp) noexcept
Sets the interpolation type for the path.
SVec3 getPosition(RealType t) const
Gets the rotational position at a given time.
InterpType
Enumeration for types of interpolation.
void addCoord(const RotationCoord &coord) noexcept
Adds a rotation coordinate to the path.
A class representing a vector in spherical coordinates.
double RealType
Type for real numbers.
Definition config.h:27
constexpr RealType PI
Mathematical constant π (pi).
Definition config.h:43
Coordinate and rotation structure operations.
Classes and operations for 3D geometry.
Definition coord.h:18
Utility functions for path interpolation and exception handling.
void getPositionLinear(RealType t, T &coord, const std::vector< T > &coords)
Performs linear interpolation between coordinate points.
Definition path_utils.h:85
void getPositionStatic(T &coord, const std::vector< T > &coords)
Interpolates a static position from a list of coordinates.
Definition path_utils.h:66
void finalizeCubic(const std::vector< T > &coords, std::vector< T > &dd)
Finalizes cubic spline interpolation by calculating second derivatives.
Definition path_utils.h:173
void getPositionCubic(RealType t, T &coord, const std::vector< T > &coords, const std::vector< T > &dd)
Performs cubic spline interpolation between coordinate points.
Definition path_utils.h:128
Defines the RotationPath class for handling rotational paths with different interpolation types.
Represents a rotation in terms of azimuth, elevation, and time.
Definition coord.h:72
RealType elevation
Elevation angle.
Definition coord.h:74
RealType azimuth
Azimuth angle.
Definition coord.h:73