Created
May 21, 2013 02:33
-
-
Save fasiha/5617162 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See pages 173 and 175 of Snyder's "Map Projections---A Working Manual" (1987): http://pubs.usgs.gov/pp/1395/report.pdf | |
function satelliteVerticalR(H, R) { | |
var P = 1.0 + H/R; | |
function forward(λ, φ) { | |
var cosφ = Math.cos(φ), | |
k = (P - 1) / (P - cosφ * Math.cos(λ)); | |
return [ | |
R * k * cosφ * Math.sin(λ), | |
R * k * Math.sin(φ) | |
]; | |
} | |
forward.invert = function(x, y) { | |
var ρ2 = x * x + y * y, | |
ρ = Math.sqrt(ρ2), | |
R2 = Math.pow(R, 2), | |
sinc = (P - Math.sqrt(1 - ρ2 * (P + 1) / (R2 * (P - 1)))) / (R * (P - 1) / ρ + ρ / (R * (P - 1))); | |
return [ | |
Math.atan2(x * sinc, ρ * Math.sqrt(1 - sinc * sinc)), | |
ρ ? asin(y * sinc / ρ) : 0 | |
]; | |
}; | |
return forward; | |
} | |
// No tilt yet | |
function satelliteProjectionR() { | |
var R = 1.0, | |
H = 0.4, | |
m = projectionMutator(satelliteVerticalR), | |
p = m(H, R); | |
p.height = function(_) { | |
if (!arguments.length) return H; | |
return m(H = +_, R); | |
}; | |
p.radius = function(_) { | |
if (!arguments.length) return R; | |
return m(P, R = +_); | |
}; | |
return p; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment