-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime-to-impact.cpp
More file actions
31 lines (24 loc) · 1.18 KB
/
time-to-impact.cpp
File metadata and controls
31 lines (24 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class ImpactEstimator {
public:
// Estimate seconds until missile reaches us
// Based on how fast intensity is growing
// Real systems use much more sophisticated kinematics, this is just a hobby project :p
double estimate(const MissileTracks& track) {
if (track.history_index < 2) return 99.0; // not enough data
// Get last two intensity readings
int curr_idx = (track.history_index - 1) % 16;
int prev_idx = (track.history_index - 2) % 16;
double current = track.intensity_history[curr_idx];
double previous = track.intensity_history[prev_idx];
if (previous <= 0.0) return 99.0;
// Intensity grows as inverse square of range
// If intensity doubled, range decreased by factor of sqrt 2
double intensity_ratio = current / previous;
if (intensity_ratio <= 1.0) return 99.0; // not closing
// Rough time-to-impact based on growth rate
// Real systems use full kinematic models
double growth_per_second = intensity_ratio * 10.0;
double time_to_impact = 100.0 / growth_per_second;
return std::max(1.0, std::min(time_to_impact, 99.0));
}
};