d3 / d3-geo-projection

Extended geographic projections for d3-geo.
https://observablehq.com/collection/@d3/d3-geo-projection
Other
1.1k stars 201 forks source link

Two-point equidistant projection has artifacts when showing the whole world #192

Closed beuan closed 4 years ago

beuan commented 4 years ago

Is there any short term plan to fix artifacts when showing the whole world with the two-point equidistant projection? https://github.com/d3/d3-geo-projection/blob/aa9e19e0da32c67f875a85ff0c6d8ce83a186e22/src/twoPointEquidistant.js#L4-L6

Fil commented 4 years ago

Not an answer to your question, but here's a modernized version, with a clip-angle of 145°: https://observablehq.com/@fil/two-point-equidistant

Fil commented 4 years ago

I have updated https://observablehq.com/@fil/two-point-equidistant with polygon clipping. The polygon in question is quite simple: it's just a rectangle that runs around the antipodes of the two centers. It covers 99.9996% of the globe ;)

two-point-equidistant

Fil commented 4 years ago

Oh and, if you want spherical ellipses, we got it covered too: https://observablehq.com/@fil/spherical-ellipses

(turns out they're not needed for this projection since we want the "largest" ellipse we can get, and that's our simple polygon).

beuan commented 4 years ago

Cool! I will have to wait for the next release, but how can I add this clipping polygon to my call?

return d3.geoTwoPointEquidistant([lon1, lat1],[lon2, lat2])
         .clipAngle(105);

Thanks! 🙏🏻

Fil commented 4 years ago

The technique works with the current releases (d3-geo@1, d3-geo-projection@2 and d3-geo-polygon@1). The relevant call is

projection.preclip(d3.geoClipPolygon(ellipse));

where ellipse is a GeoJSON polygon that goes “around” the antipodes of the two centers a and b (in the rotation that puts them symmetrically around [0,0] on the equator):

const eps = 1e-3, u = (d3.geoDistance(a, b) / 2) * degrees + eps,
  ellipse = {
    type: "Polygon",
    coordinates: [[
        [180 - u, eps],
        [180 - u, -eps],
        [-180 + u, -eps],
        [-180 + u, eps],
        [180 - u, eps]
      ]]
  };
beuan commented 4 years ago

Sweet! It works like a charm. Thank you for your help, @Fil! 🙏🏻