News for hackers. Stuff that matters.
Re:I cheated on my Microsoft interview (2019) by gshubert17 on Wednesday June 15, 2022 @03:21PM (#31758033)
I think I found a small typo, where you have delta (instead of delta/2) in the third line. I believe it should be

sqrt(h(2R+h))-R * arccos(R/(R+h))-delta/2 = 0

This can be solved for h given delta numerically, such as with a spreadsheet. Use caution here because this formula leads to a loss of significant digits from cancellation of nearly identical terms.

For example, given R = 6378000 meters and trying h = 193 meters: the first (d) term is 49618.0 meters and the second (s) term is 49617.0 meters. The difference is 1.0 meter, which is the half delta we wanted. But there's been a loss of 4 significant digits (because the first 4 digits in each value are the same: 4961). The smaller the arc distance, the smaller the angle, the worse the relative error becomes.

It's possible to analytically factor out sqrt(2hR) from both the d and s terms. In the first case,

d = sqrt(2Rh+h^2) = sqrt(2Rh) * (1+h/4R) using Taylor series for (1+h^2/2Rh)^0.5

In the second case, I can derive one formula, but the coefficients aren't the same as my numerical best fit, which is

s = sqrt(2Rh) * (1-5h/12R)

Combining the two series versions for d and s, gives us this for delta,

delta = 4h/3 * sqrt(2h/R)

Finally, solving for h given delta, take the cube root of h^3:

h^3 = (9R/32) * delta^2

Thus for a delta of 2 meters, I get height h = 192.88 meters.

There are no comments on this comment yet.