Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add d3.geo.ginzburg{4,5,6,8,9}.

  • Loading branch information...
commit ab8807491da463be03a96d7df68e0556da47b6d3 1 parent 3738859
@jasondavies jasondavies authored
View
5 geo/projection/README.md
@@ -29,6 +29,11 @@ Projections:
* d3.geo.equirectangular - [Equirectangular (Plate Carrée)](http://bl.ocks.org/mbostock/3757119)
* d3.geo.fahey - [Fahey](http://bl.ocks.org/mbostock/4731228)
* d3.geo.gallStereographic - [Gall’s stereographic](http://bl.ocks.org/mbostock/5234763)
+* d3.geo.ginzburg4 - Ginzburg IV
+* d3.geo.ginzburg5 - Ginzburg V
+* d3.geo.ginzburg6 - Ginzburg VI
+* d3.geo.ginzburg8 - Ginzburg VIII
+* d3.geo.ginzburg9 - Ginzburg IX
* d3.geo.gnomonic - [gnomonic](http://bl.ocks.org/mbostock/3757349)
* d3.geo.gringorten - [Gringorten](http://bl.ocks.org/mbostock/4362031)
* d3.geo.guyou - [Guyou hemisphere-in-a-square](http://bl.ocks.org/mbostock/3763867)
View
56 geo/projection/ginzburg-polyconic.js
@@ -0,0 +1,56 @@
+import "math";
+
+function ginzburgPolyconic(a, b, c, d, e, f, g, h) {
+ if (arguments.length < 8) h = 0;
+
+ function forward(λ, φ) {
+ if (!φ) return [a * λ / π, 0];
+ var φ2 = φ * φ,
+ xB = a + φ2 * (b + φ2 * (c + φ2 * d)),
+ yB = φ * (e - 1 + φ2 * (f - h + φ2 * g)),
+ m = (xB * xB + yB * yB) / (2 * yB),
+ α = λ * Math.asin(xB / m) / π;
+ return [m * Math.sin(α), φ * (1 + φ2 * h) + m * (1 - Math.cos(α))];
+ }
+
+ forward.invert = function(x, y) {
+ var λ = π * x / a,
+ φ = y,
+ δλ, δφ, i = 50;
+ do {
+ var φ2 = φ * φ,
+ xB = a + φ2 * (b + φ2 * (c + φ2 * d)),
+ yB = φ * (e - 1 + φ2 * (f - h + φ2 * g)),
+ p = xB * xB + yB * yB,
+ q = 2 * yB,
+ m = p / q,
+ m2 = m * m,
+ dαdλ = Math.asin(xB / m) / π,
+ α = λ * dαdλ;
+ xB2 = xB * xB,
+ dxBdφ = (2 * b + φ2 * (4 * c + φ2 * 6 * d)) * φ,
+ dyBdφ = e + φ2 * (3 * f + φ2 * 5 * g),
+ dpdφ = 2 * (xB * dxBdφ + yB * (dyBdφ - 1)),
+ dqdφ = 2 * (dyBdφ - 1),
+ dmdφ = (dpdφ * q - p * dqdφ) / (q * q),
+ cosα = Math.cos(α),
+ sinα = Math.sin(α),
+ mcosα = m * cosα,
+ msinα = m * sinα,
+ dαdφ = ((λ / π) * (1 / asqrt(1 - xB2 / m2)) * (dxBdφ * m - xB * dmdφ)) / m2,
+ fx = msinα - x,
+ fy = φ * (1 + φ2 * h) + m - mcosα - y,
+ δxδφ = dmdφ * sinα + mcosα * dαdφ,
+ δxδλ = mcosα * dαdλ,
+ δyδφ = 1 + dmdφ - (dmdφ * cosα - msinα * dαdφ),
+ δyδλ = msinα * dαdλ,
+ denominator = δxδφ * δyδλ - δyδφ * δxδλ;
+ if (!denominator) break;
+ λ -= δλ = (fy * δxδφ - fx * δyδφ) / denominator;
+ φ -= δφ = (fx * δyδλ - fy * δxδλ) / denominator;
+ } while ((Math.abs(δλ) > ε || Math.abs(δφ) > ε) && --i > 0);
+ return [λ, φ];
+ };
+
+ return forward;
+}
View
6 geo/projection/ginzburg4.js
@@ -0,0 +1,6 @@
+import "projection";
+import "ginzburg-polyconic";
+
+var ginzburg4 = ginzburgPolyconic(2.8284, -1.6988, .75432, -.18071, 1.76003, -.38914, .042555);
+
+(d3.geo.ginzburg4 = function() { return projection(ginzburg4); }).raw = ginzburg4;
View
6 geo/projection/ginzburg5.js
@@ -0,0 +1,6 @@
+import "projection";
+import "ginzburg-polyconic";
+
+var ginzburg5 = ginzburgPolyconic(2.583819, -.835827, .170354, -.038094, 1.543313, -.411435, .082742);
+
+(d3.geo.ginzburg5 = function() { return projection(ginzburg5); }).raw = ginzburg5;
View
6 geo/projection/ginzburg6.js
@@ -0,0 +1,6 @@
+import "projection";
+import "ginzburg-polyconic";
+
+var ginzburg6 = ginzburgPolyconic(5 / 6 * π, -.62636, -.0344, 0, 1.3493, -.05524, 0, .045);
+
+(d3.geo.ginzburg6 = function() { return projection(ginzburg6); }).raw = ginzburg6;
View
29 geo/projection/ginzburg8.js
@@ -0,0 +1,29 @@
+import "projection";
+
+function ginzburg8(λ, φ) {
+ var λ2 = λ * λ,
+ φ2 = φ * φ;
+ return [
+ λ * (1 - .162388 * φ2) * (.87 - .000952426 * λ2 * λ2),
+ φ * (1 + φ2 / 12)
+ ];
+}
+
+ginzburg8.invert = function(x, y) {
+ var λ = x,
+ φ = y,
+ i = 50, δ;
+ do {
+ var φ2 = φ * φ;
+ φ -= δ =* (1 + φ2 / 12) - y) / (1 + φ2 / 4);
+ } while (Math.abs(δ) > ε && --i > 0);
+ i = 50;
+ x /= 1 - .162388 * φ2;
+ do {
+ var λ4 =4 = λ * λ) * λ4;
+ λ -= δ =* (.87 - .000952426 * λ4) - x) / (.87 - .00476213 * λ4);
+ } while (Math.abs(δ) > ε && --i > 0);
+ return [λ, φ];
+};
+
+(d3.geo.ginzburg8 = function() { return projection(ginzburg8); }).raw = ginzburg8;
View
6 geo/projection/ginzburg9.js
@@ -0,0 +1,6 @@
+import "projection";
+import "ginzburg-polyconic";
+
+var ginzburg9 = ginzburgPolyconic(2.6516, -.76534, .19123, -.047094, 1.36289, -.13965, .031762);
+
+(d3.geo.ginzburg9 = function() { return projection(ginzburg9); }).raw = ginzburg9;
View
5 geo/projection/index.js
@@ -21,6 +21,11 @@ import "eckert6";
import "eisenlohr";
import "fahey";
import "gall-stereographic";
+import "ginzburg4";
+import "ginzburg5";
+import "ginzburg6";
+import "ginzburg8";
+import "ginzburg9";
import "gringorten";
import "guyou";
import "hammer-retroazimuthal";
View
28 geo/projection/test/ginzburg4-test.js
@@ -0,0 +1,28 @@
+var vows = require("vows"),
+ assert = require("./assert"),
+ load = require("./load");
+
+var suite = vows.describe("d3.geo.ginzburg4");
+
+suite.addBatch({
+ "ginzburg4": {
+ topic: load("ginzburg4"),
+ "default": {
+ topic: function(geo) { return geo.ginzburg4(); },
+ "projections and inverse projections": function(ginzburg4) {
+ assert.equalInverse(ginzburg4, [ 0, 0], [480, 250]);
+ assert.equalInverse(ginzburg4, [ 0, -90], [480, 485.619449]);
+ assert.equalInverse(ginzburg4, [ 0, 90], [480, 14.380550]);
+ assert.equalInverse(ginzburg4, [ 0, -45], [480, 367.809724]);
+ assert.equalInverse(ginzburg4, [ 0, 45], [480, 132.190275]);
+ assert.equalInverse(ginzburg4, [-180, 0], [ 55.74, 250]);
+ assert.equalInverse(ginzburg4, [ 180, 0], [904.26, 250]);
+ assert.equalInverse(ginzburg4, [-179, 15], [ 74.930232, 182.241971]);
+ assert.equalInverse(ginzburg4, [-179, 80], [324.146655, 6.768973]);
+ assert.equalInverse(ginzburg4, [ 1, 1], [482.356603, 247.381944]);
+ }
+ }
+ }
+});
+
+suite.export(module);
View
28 geo/projection/test/ginzburg5-test.js
@@ -0,0 +1,28 @@
+var vows = require("vows"),
+ assert = require("./assert"),
+ load = require("./load");
+
+var suite = vows.describe("d3.geo.ginzburg5");
+
+suite.addBatch({
+ "ginzburg5": {
+ topic: load("ginzburg5"),
+ "default": {
+ topic: function(geo) { return geo.ginzburg5(); },
+ "projections and inverse projections": function(ginzburg5) {
+ assert.equalInverse(ginzburg5, [ 0, 0], [480, 250]);
+ assert.equalInverse(ginzburg5, [ 0, -90], [480, 485.619449]);
+ assert.equalInverse(ginzburg5, [ 0, 90], [480, 14.380550]);
+ assert.equalInverse(ginzburg5, [ 0, -45], [480, 367.809724]);
+ assert.equalInverse(ginzburg5, [ 0, 45], [480, 132.190275]);
+ assert.equalInverse(ginzburg5, [-180, 0], [92.4271500, 250]);
+ assert.equalInverse(ginzburg5, [ 180, 0], [867.572850, 250]);
+ assert.equalInverse(ginzburg5, [-179, 15], [103.000122, 190.710455]);
+ assert.equalInverse(ginzburg5, [-179, 80], [283.164027, 29.027751]);
+ assert.equalInverse(ginzburg5, [ 1, 1], [482.152989, 247.381962]);
+ }
+ }
+ }
+});
+
+suite.export(module);
View
28 geo/projection/test/ginzburg6-test.js
@@ -0,0 +1,28 @@
+var vows = require("vows"),
+ assert = require("./assert"),
+ load = require("./load");
+
+var suite = vows.describe("d3.geo.ginzburg6");
+
+suite.addBatch({
+ "ginzburg6": {
+ topic: load("ginzburg6"),
+ "default": {
+ topic: function(geo) { return geo.ginzburg6(); },
+ "projections and inverse projections": function(ginzburg6) {
+ assert.equalInverse(ginzburg6, [ 0, 0], [480, 250]);
+ assert.equalInverse(ginzburg6, [ 0, -90], [480, 511.780994], 1e-4);
+ assert.equalInverse(ginzburg6, [ 0, 90], [480, -11.780994], 1e-4);
+ assert.equalInverse(ginzburg6, [ 0, -45], [480, 371.079917], 1e-5);
+ assert.equalInverse(ginzburg6, [ 0, 45], [480, 128.920082], 1e-5);
+ assert.equalInverse(ginzburg6, [-180, 0], [ 87.300918, 250]);
+ assert.equalInverse(ginzburg6, [ 180, 0], [872.699081, 250]);
+ assert.equalInverse(ginzburg6, [-179, 15], [ 95.906977, 197.310730]);
+ assert.equalInverse(ginzburg6, [-179, 80], [291.096338, -9.687754]);
+ assert.equalInverse(ginzburg6, [ 1, 1], [482.181510, 247.381942]);
+ }
+ }
+ }
+});
+
+suite.export(module);
View
28 geo/projection/test/ginzburg8-test.js
@@ -0,0 +1,28 @@
+var vows = require("vows"),
+ assert = require("./assert"),
+ load = require("./load");
+
+var suite = vows.describe("d3.geo.ginzburg8");
+
+suite.addBatch({
+ "ginzburg8": {
+ topic: load("ginzburg8"),
+ "default": {
+ topic: function(geo) { return geo.ginzburg8(); },
+ "projections and inverse projections": function(ginzburg8) {
+ assert.equalInverse(ginzburg8, [ 0, 0], [480, 250]);
+ assert.equalInverse(ginzburg8, [ 0, -90], [480, 534.066756]);
+ assert.equalInverse(ginzburg8, [ 0, 90], [480, -34.066756]);
+ assert.equalInverse(ginzburg8, [ 0, -45], [480, 373.865637]);
+ assert.equalInverse(ginzburg8, [ 0, 45], [480, 126.134362]);
+ assert.equalInverse(ginzburg8, [-180, 0], [113.741324, 250]);
+ assert.equalInverse(ginzburg8, [ 180, 0], [846.258675, 250]);
+ assert.equalInverse(ginzburg8, [-179, 15], [118.882415, 210.505798], 1e-5);
+ assert.equalInverse(ginzburg8, [-179, 80], [230.428677, 6.534397]);
+ assert.equalInverse(ginzburg8, [ 1, 1], [482.277542, 247.381939]);
+ }
+ }
+ }
+});
+
+suite.export(module);
View
28 geo/projection/test/ginzburg9-test.js
@@ -0,0 +1,28 @@
+var vows = require("vows"),
+ assert = require("./assert"),
+ load = require("./load");
+
+var suite = vows.describe("d3.geo.ginzburg9");
+
+suite.addBatch({
+ "ginzburg9": {
+ topic: load("ginzburg9"),
+ "default": {
+ topic: function(geo) { return geo.ginzburg9(); },
+ "projections and inverse projections": function(ginzburg9) {
+ assert.equalInverse(ginzburg9, [ 0, 0], [480, 250]);
+ assert.equalInverse(ginzburg9, [ 0, -90], [480, 485.619449]);
+ assert.equalInverse(ginzburg9, [ 0, 90], [480, 14.380550]);
+ assert.equalInverse(ginzburg9, [ 0, -45], [480, 367.809724]);
+ assert.equalInverse(ginzburg9, [ 0, 45], [480, 132.190275]);
+ assert.equalInverse(ginzburg9, [-180, 0], [ 82.26, 250]);
+ assert.equalInverse(ginzburg9, [ 180, 0], [877.74, 250]);
+ assert.equalInverse(ginzburg9, [-179, 15], [ 92.158925, 197.003182]);
+ assert.equalInverse(ginzburg9, [-179, 80], [250.610739, -3.220862]);
+ assert.equalInverse(ginzburg9, [ 1, 1], [482.209480, 247.381976]);
+ }
+ }
+ }
+});
+
+suite.export(module);
Please sign in to comment.
Something went wrong with that request. Please try again.