Skip to content

Commit

Permalink
Added hill
Browse files Browse the repository at this point in the history
  • Loading branch information
mbloch committed May 24, 2021
1 parent aa2f507 commit 693607e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v0.0.33
* Added Hill Eucyclic projection.

v0.0.32
* Bug fix

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mproj",
"version": "0.0.32",
"version": "0.0.33",
"description": "A JavaScript port of the Proj.4 cartographic projections library",
"keywords": [
"projections",
Expand Down
2 changes: 1 addition & 1 deletion src/projections/bertin1953.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Port to PROJ by Philippe Rivière, 21 September 2018
Port to JavaScript by Matthew Bloch October 2018
*/
pj_add(pj_bertin1953, 'bertin1953', 'Bertin 1953', 'Misc Sph no inv.');
pj_add(pj_bertin1953, 'bertin1953', 'Bertin 1953', 'Misc., Sph., NoInv.');

function pj_bertin1953(P) {
var cos_delta_phi, sin_delta_phi, cos_delta_gamma, sin_delta_gamma;
Expand Down
2 changes: 1 addition & 1 deletion src/projections/cupola.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pj_add(pj_cupola, 'cupola', 'Cupola', 'Misc., Sph., NoInv.');
pj_add(pj_cupola, 'cupola', 'Cupola', 'PCyl., Sph., NoInv.');

// Source: https://www.tandfonline.com/eprint/EE7Y8RK4GXA4ITWUTQPY/full?target=10.1080/23729333.2020.1862962
// See also: http://www.at-a-lanta.nl/weia/cupola.html
Expand Down
58 changes: 58 additions & 0 deletions src/projections/hill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
pj_add(pj_hill, 'hill', 'Hill Eucyclic', 'PCyl., Sph., NoInv.');

// Adapted from: https://github.com/d3/d3-geo-projection/blob/master/src/hill.js
// License: https://github.com/d3/d3-geo-projection/blob/master/LICENSE

function pj_hill(P) {
var K = 1, // TODO: expose as parameter
L = 1 + K,
sinBt = sin(1 / L),
Bt = asin(sinBt),
A = 2 * sqrt(M_PI / (B = M_PI + 4 * Bt * L)),
B,
rho0 = 0.5 * A * (L + sqrt(K * (2 + K))),
K2 = K * K,
L2 = L * L,
EPS = 1e-12;

P.es = 0;
P.fwd = s_fwd;
P.inv = s_inv;

function s_fwd(lp, xy) {
var t = 1 - sin(lp.phi),
rho, omega;
if (t && t < 2) {
var theta = M_HALFPI - lp.phi,
i = 25,
delta, sinTheta, cosTheta, C, Bt_Bt1;
do {
sinTheta = sin(theta);
cosTheta = cos(theta);
Bt_Bt1 = Bt + atan2(sinTheta, L - cosTheta);
C = 1 + L2 - 2 * L * cosTheta;
theta -= delta = (theta - K2 * Bt - L * sinTheta + C * Bt_Bt1 -0.5 * t * B) / (2 * L * sinTheta * Bt_Bt1);
} while (fabs(delta) > EPS && --i > 0);
rho = A * sqrt(C);
omega = lp.lam * Bt_Bt1 / M_PI;
} else {
rho = A * (K + t);
omega = lp.lam * Bt / M_PI;
}

xy.x = rho * sin(omega);
xy.y = rho0 - rho * cos(omega);
}

function s_inv(xy, lp) {
var x = xy.x,
y = xy.y,
rho2 = x * x + (y -= rho0) * y,
cosTheta = (1 + L2 - rho2 / (A * A)) / (2 * L),
theta = acos(cosTheta),
sinTheta = sin(theta),
Bt_Bt1 = Bt + atan2(sinTheta, L - cosTheta);
lp.lam = asin(x / sqrt(rho2)) * M_PI / Bt_Bt1,
lp.phi = asin(1 - 2 * (theta - K2 * Bt - L * sinTheta + (1 + L2 - 2 * L * cosTheta) * Bt_Bt1) / B);
}
}

0 comments on commit 693607e

Please sign in to comment.