Published
Edited
Nov 18, 2020
1 fork
15 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
C0 = [90, 90 - colat]
Insert cell
C1 = [-90, 90 - colat]
Insert cell
ellipse = geoEllipse(C0, C1, radius)
Insert cell
projection = d3
.geoOrthographic()
.rotate([20, -65])
.precision(0.1)
Insert cell
function geoEllipse(p0, p1, radius) {
const precision = 6; // see geoCircle
const i = d3.geoInterpolate(p0, p1),
alpha = i.distance / 2,
theta = radius * radians,
A = tan(alpha),
A2 = A * A,
D = tan(theta),
D2 = D * D,
R = 1 / sqrt(1 + D2),
Z = R * D,
Y = R * sqrt(D2 - A2);

if (alpha > pi / 2 || theta < alpha) return null;
if (theta >= pi - alpha) return { type: "Sphere" };

// calculate an ellipse centered on [0,0] and aligned on the equator
let ring = [];
for (let i = 0; i < 360; i += precision) {
const t = i * radians,
c = cos(t),
s = sin(t);
const y = s * Z,
z = c * Y,
x = sqrt(1 - y * y - z * z) * Math.sign(D);
ring.push(spherical([x, y, z]).map(d => d * degrees));
}

ring.push(ring[0]);
if (D < 0) ring.reverse();

// rotate to align it with the actual points
const o = i(0.5),
a = d3.geoRotation([-o[0], -o[1]])(p0),
b = i.distance / 2,
y = -asin(sin(a[1] * radians) / sin(b)),
r = [-o[0], -o[1], -(a[0] > 0 ? pi - y : y) * degrees];

return {
type: "Polygon",
coordinates: [ring.map(d3.geoRotation(r).invert)]
};
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3@6", "d3-geo-projection@3", "d3-geo-polygon@1")
Insert cell
height = 550
Insert cell
import { asin, cos, degrees, pi, radians, sin, sqrt, tan } from "@fil/math"
Insert cell
import { spherical } from "@fil/cartesian"
Insert cell
import { zoom } from "@d3/versor-zooming"
Insert cell
import { slider } from "@jashkenas/inputs"
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more