Skip to content

Commit 71542f6

Browse files
committed
Add "gnomonic" mode to azimuthal projection.
Also, moved d3_radians to src/geo/geo.js.
1 parent e09f19c commit 71542f6

7 files changed

Lines changed: 69 additions & 11 deletions

File tree

d3.geo.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
(function(){d3.geo = {};
2+
3+
var d3_radians = Math.PI / 180;
24
// TODO clip input coordinates on opposite hemisphere
35
d3.geo.azimuthal = function() {
46
var mode = "orthographic", // or stereographic
@@ -17,7 +19,9 @@ d3.geo.azimuthal = function() {
1719
sx1 = Math.sin(x1),
1820
cy1 = Math.cos(y1),
1921
sy1 = Math.sin(y1),
20-
k = mode === "stereographic" ? 1 / (1 + sy0 * sy1 + cy0 * cy1 * cx1) : 1,
22+
k = mode === "stereographic" ? 1 / (sy0 * sy1 + cy0 * cy1 * cx1 + 1)
23+
: mode === "gnomonic" ? 1 / (sy0 * sy1 + cy0 * cy1 * cx1)
24+
: 1,
2125
x = k * cy1 * sx1,
2226
y = k * (sy0 * cy1 * cx1 - cy0 * sy1);
2327
return [
@@ -30,7 +34,9 @@ d3.geo.azimuthal = function() {
3034
var x = (coordinates[0] - translate[0]) / scale,
3135
y = (coordinates[1] - translate[1]) / scale,
3236
p = Math.sqrt(x * x + y * y),
33-
c = mode === "stereographic" ? 2 * Math.atan(p) : Math.asin(p),
37+
c = mode === "stereographic" ? 2 * Math.atan(p)
38+
: mode === "gnomonic" ? Math.atan(p)
39+
: Math.asin(p),
3440
sc = Math.sin(c),
3541
cc = Math.cos(c);
3642
return [
@@ -195,8 +201,6 @@ d3.geo.albersUsa = function() {
195201

196202
return albersUsa.scale(lower48.scale());
197203
};
198-
199-
var d3_radians = Math.PI / 180;
200204
d3.geo.mercator = function() {
201205
var scale = 500,
202206
translate = [480, 250];

d3.geo.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/azimuthal/azimuthal.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
5-
<title>Polar Stereographic Projection</title>
5+
<title>Azimuthal Projection</title>
66
<script type="text/javascript" src="../../d3.js"></script>
77
<script type="text/javascript" src="../../d3.geo.js"></script>
88
<script type="text/javascript" src="../../lib/jquery/jquery.min.js"></script>

src/geo/albers.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,3 @@ d3.geo.albersUsa = function() {
124124

125125
return albersUsa.scale(lower48.scale());
126126
};
127-
128-
var d3_radians = Math.PI / 180;

src/geo/azimuthal.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ d3.geo.azimuthal = function() {
1616
sx1 = Math.sin(x1),
1717
cy1 = Math.cos(y1),
1818
sy1 = Math.sin(y1),
19-
k = mode === "stereographic" ? 1 / (1 + sy0 * sy1 + cy0 * cy1 * cx1) : 1,
19+
k = mode === "stereographic" ? 1 / (sy0 * sy1 + cy0 * cy1 * cx1 + 1)
20+
: mode === "gnomonic" ? 1 / (sy0 * sy1 + cy0 * cy1 * cx1)
21+
: 1,
2022
x = k * cy1 * sx1,
2123
y = k * (sy0 * cy1 * cx1 - cy0 * sy1);
2224
return [
@@ -29,7 +31,9 @@ d3.geo.azimuthal = function() {
2931
var x = (coordinates[0] - translate[0]) / scale,
3032
y = (coordinates[1] - translate[1]) / scale,
3133
p = Math.sqrt(x * x + y * y),
32-
c = mode === "stereographic" ? 2 * Math.atan(p) : Math.asin(p),
34+
c = mode === "stereographic" ? 2 * Math.atan(p)
35+
: mode === "gnomonic" ? Math.atan(p)
36+
: Math.asin(p),
3337
sc = Math.sin(c),
3438
cc = Math.cos(c);
3539
return [

src/geo/geo.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
d3.geo = {};
2+
3+
var d3_radians = Math.PI / 180;

0 commit comments

Comments
 (0)