Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distance is not calculated well #3

Open
CryptoPunk opened this issue Sep 2, 2016 · 8 comments
Open

Distance is not calculated well #3

CryptoPunk opened this issue Sep 2, 2016 · 8 comments

Comments

@CryptoPunk
Copy link

The formula laid out doesn't caluclate distance well, as line of sight is not the measure of distance across a globe. instead I would make the assumption that the distance is an arc segment. This has the added benefit that when d_surface_0 < d_surface_1, the heigh for an obscuring object is calculated.

Example python code

from math import pi,inf,acos,cos
R=6371*1000
h_1 = 2
d_surf_0 = R*pi

theta_1 = acos(R/(h_1+R))
d_surf_1 = R*theta_1
print("horizon: %.02f" % d_surf_1)
d_surf_2 = d_surf_0 - d_surf_1
theta_2 = d_surf_2/R
if theta_2 > pi/2:
    h_2 = inf
else:
    h_2 = R/cos(theta_2)-R

print("height: %.02f" % h_2)
@CryptoPunk
Copy link
Author

CryptoPunk commented Sep 2, 2016

To add a bit more, the divergence becomes quite obvious if you enter a distance that is half the circumference of the earth, which you should never see over the horizon since it's on the other side of the world. It's impossible to see more anything no matter how tall if it's more than 1/4 the circumference from the horizon, since the growth in height would be parallel to the horizon.

@dcoffm
Copy link

dcoffm commented Sep 2, 2016

I would point out that your claim on the 1/4th circumference is not true. If you and the other object were both tall enough, you could see each other at all angles except for theta = pi. You'd have to be very tall (h >> R) but there is no need for an imposed inf value, as it comes naturally from the trig functions.

https://www.desmos.com/calculator/neu5mpm5v4
If you look at this graph I made some time ago and zoom out far enough, you can see that it repeats periodically with the circumference of the earth, which makes sense because if you go around the earth you will eventually be able to see it again.

@dcoffm
Copy link

dcoffm commented Sep 2, 2016

But in general I agree with the point about using arclengths instead of direct distance, since it is easy to measure GPS location and calculate surface distance. For almost any application, casual or otherwise, you will know your surface coordinates and altitude.

@CryptoPunk
Copy link
Author

CryptoPunk commented Nov 30, 2016

Sorry, didnt see you had responded to this.

I think I didn't explain myself clearly. It's not 1/4 the distance from the observer, it's 1/4 the distance from the horizon point. Since the line of sight to the horizon touches the circle of the earth, it can be assumed that it is a tangent line. In your drawing, L'+L, or D. A ray drawn outwards from the circle, 90 degrees from the tangent intersection line, R would be parallel forever. This is exemplified in the identity tan(pi/2) = NaN.

Additionally, you would need to impose an infinite value because when using the cosine theta_2, when theta_2 is beyond pi/2 radians from the tangent point, you wind up with negative values, which are meaningless in this context since height cannot be negative.

Also, your graph is showing an error. L is not equal to R*theta in the drawing. R*theta is distance of the arc segment drawn between the lines R+h and R (An unlabeled arc segment). What you are going for is L=R*tan(theta). That error bubbles through the formula, causing the periodic behavior. If you look at the image and imagine extending the L' line out to infinity, you can see that it would be impossible to ever be periodic. (D is not circular)

@dcoffm
Copy link

dcoffm commented Nov 30, 2016

I'm afraid you've misinterpreted the drawing. I specifically emphasized in the caption that L, L' and D are arclengths. The nature of the drawing is such that it looks like they are labeling the tangent lines, but they simply aren't. L describes the distance along the surface you would travel in going from ray R to ray R+h. The direct distance between points is never used in the calculation; indeed the only reason the tangent line is there is to illustrate that they are right triangles and allow for theta = acos (R/(R+h)).

D is, in fact, circular, so the result should absolutely be periodic. Do you have a problem with the calculation now that that's been cleared up?

@CryptoPunk
Copy link
Author

CryptoPunk commented Nov 30, 2016

I have indeed. In that case it looks good, and it's getting the same results as my python implementation, differently derived, should have checked that first. Infact, graphing them together, we have exactly the same implementation.

Your implementation does have negatives though, as does mine for the reasons that I stated earlier. The negative maxima on your selected scale is at (y=-4.1852*10^7). Additionally, there are undefined points at the asymtotes, the first one being at (20926000/5280) * (pi/2) + (20926000*acos(20926000/(20926000+h)))/5280. Same as mine, because we have the same implementation.

@dcoffm
Copy link

dcoffm commented Nov 30, 2016

You are right that there are negatives outside of the visible angles. I decided to make another graph which actually plots the situation in addition to calculating: https://www.desmos.com/calculator/ncx9b8ojzv

@tarangmungole
Copy link

This calculation is perfect mathematically. I plot the website's calculations vs using distance correction (i.e. distance measured on the surface, which is more correct). To my wonder, the calculator is perfect.
Picture2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants