Skip to content

Commit d9c80c2

Browse files
committed
Add interpolation to azimuth history
1 parent 91efdbb commit d9c80c2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main/java/org/mayheminc/util/History.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,16 @@ public double getAzForTime(double t) {
4141
}
4242

4343
if (time[i] <= t) {
44-
az = azimuth[i];
44+
int prev = (i + 1) % HISTORY_SIZE;
45+
if (prev != index) {
46+
// Interpolate between the two closest entries
47+
assert(time[i] < time[prev]);
48+
double factor = (t - time[i]) / (time[prev] - time[i]);
49+
az = azimuth[i] + factor * (azimuth[prev] - azimuth[i]);
50+
} else {
51+
// Only one entry; no interpolation possible
52+
az = azimuth[i];
53+
}
4554
break;
4655
}
4756

0 commit comments

Comments
 (0)