source: Dev/trunk/d3/src/geo/azimuthal.js @ 76

Last change on this file since 76 was 76, checked in by fpvanagthoven, 14 years ago

d3

File size: 1.3 KB
Line 
1// TODO clip input coordinates on opposite hemisphere
2d3.geo.azimuthal = function() {
3  var mode = "orthographic", // or stereographic
4      origin,
5      scale = 200,
6      translate = [480, 250],
7      x0,
8      y0,
9      cy0,
10      sy0;
11
12  function azimuthal(coordinates) {
13    var x1 = coordinates[0] * d3_radians - x0,
14        y1 = coordinates[1] * d3_radians,
15        cx1 = Math.cos(x1),
16        sx1 = Math.sin(x1),
17        cy1 = Math.cos(y1),
18        sy1 = Math.sin(y1),
19        k = mode == "stereographic" ? 1 / (1 + sy0 * sy1 + cy0 * cy1 * cx1) : 1,
20        x = k * cy1 * sx1,
21        y = k * (sy0 * cy1 * cx1 - cy0 * sy1);
22    return [
23      scale * x + translate[0],
24      scale * y + translate[1]
25    ];
26  }
27
28  azimuthal.mode = function(x) {
29    if (!arguments.length) return mode;
30    mode = x;
31    return azimuthal;
32  };
33
34  azimuthal.origin = function(x) {
35    if (!arguments.length) return origin;
36    origin = x;
37    x0 = origin[0] * d3_radians;
38    y0 = origin[1] * d3_radians;
39    cy0 = Math.cos(y0);
40    sy0 = Math.sin(y0);
41    return azimuthal;
42  };
43
44  azimuthal.scale = function(x) {
45    if (!arguments.length) return scale;
46    scale = +x;
47    return azimuthal;
48  };
49
50  azimuthal.translate = function(x) {
51    if (!arguments.length) return translate;
52    translate = [+x[0], +x[1]];
53    return azimuthal;
54  };
55
56  return azimuthal.origin([0, 0]);
57};
Note: See TracBrowser for help on using the repository browser.