Skip to content

Instantly share code, notes, and snippets.

@fasiha
Created May 21, 2013 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fasiha/5617162 to your computer and use it in GitHub Desktop.
Save fasiha/5617162 to your computer and use it in GitHub Desktop.
// 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