Skip to content
This repository has been archived by the owner on Nov 7, 2018. It is now read-only.

Commit

Permalink
Add Gilbert’s Two-World Perspective.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasondavies committed May 28, 2013
1 parent b91ab3e commit 41dac22
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions geo/projection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Projections:
* equirectangular - [Equirectangular (Plate Carrée)](http://bl.ocks.org/mbostock/3757119)
* fahey - [Fahey](http://bl.ocks.org/mbostock/4731228)
* gallStereographic - [Gall’s stereographic](http://bl.ocks.org/mbostock/5234763)
* gilbert - Gilbert’s two-world perspective
* ginzburg4 - [Ginzburg IV](http://bl.ocks.org/mbostock/5288565)
* ginzburg5 - [Ginzburg V](http://bl.ocks.org/mbostock/5288571)
* ginzburg6 - [Ginzburg VI](http://bl.ocks.org/mbostock/5288577)
Expand Down
36 changes: 36 additions & 0 deletions geo/projection/gilbert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import "projection";

function gilbert(λ, φ) {
return d3.geo.orthographic.raw(λ * .5, asin(Math.tan(φ * .5)));
}

gilbert.invert = function(x, y) {
var coordinates = d3.geo.orthographic.raw.invert(x, y);
coordinates[0] *= 2;
coordinates[1] = 2 * Math.atan(Math.sin(coordinates[1]));
};

function gilbertProjection() {
var p = projection(gilbert),
e = d3.geo.equirectangular().scale(degrees).translate([0, 0]),
o = d3.geo.orthographic();

p.stream = function(stream) {
stream = o.stream(stream);
var s = e.stream({
point: function(λ, φ) {
stream.point(λ * .5, asin(Math.tan(-φ * .5 * radians)) * degrees);
},
lineStart: function() { stream.lineStart(); },
lineEnd: function() { stream.lineEnd(); },
polygonStart: function() { stream.polygonStart(); },
polygonEnd: function() { stream.polygonEnd(); }
});
s.sphere = function() { stream.sphere(); };
return s;
};

return d3.rebind(p, o, "rotate", "scale", "translate", "clipAngle", "precision");
}

(d3.geo.gilbert = gilbertProjection).raw = gilbert;
1 change: 1 addition & 0 deletions geo/projection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import "eckert6";
import "eisenlohr";
import "fahey";
import "gall-stereographic";
import "gilbert";
import "ginzburg4";
import "ginzburg5";
import "ginzburg6";
Expand Down

0 comments on commit 41dac22

Please sign in to comment.