Skip to content

Instantly share code, notes, and snippets.

@alireza-ebrahimi
Created December 12, 2018 22:24
Show Gist options
  • Save alireza-ebrahimi/3c67fb6d34037e4d486e99ec55a9d1d1 to your computer and use it in GitHub Desktop.
Save alireza-ebrahimi/3c67fb6d34037e4d486e99ec55a9d1d1 to your computer and use it in GitHub Desktop.
function pow2(x) {
return x * x
}
function alpha(r, a, b) {
var c = -Math.sqrt((pow2(a) + 2 * r * a) / pow2(r))
var d = (r + a) / (r + b)
var eq_a = pow2(c) + 1
var eq_b = 2 * c * d
var eq_c = pow2(d) - 1
var sin_alpha = (-eq_b + Math.sqrt(pow2(eq_b) - 4 * eq_a * eq_c)) / (2 * eq_a)
return Math.asin(sin_alpha)
}
var damavand = 5.61
var karkas = 3.87
var earth_radius = 6371.0
var human_height = 0.0018
max_d = alpha(earth_radius, damavand, karkas) * earth_radius
human_d = alpha(earth_radius, 0, human_height) * earth_radius
console.log('maximum distance = ' + max_d + ' km')
console.log('maximum distance for human = ' + human_d + ' km')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment