Skip to content

Instantly share code, notes, and snippets.

@patricksurry
patricksurry / README.md
Last active February 15, 2017 13:49 — forked from mbostock/.block
D3 3D globe trackball rotation

This example illustrates a simple trackball approach for rotating an orthographic globe ' with D3 3.0.

The idea is to express a click on the sphere in spherical coordinates with one rotation axis horizontal on the page, and one axis vertical. Then when we move the mouse, we just rotate the underlying sphere so that the point of initial click stays underneath the mouse. When the globe is oriented in its original location (i.e. rotation(0,0), with the north pole at the top of the page and the equator aligned with the horizontal canvas axis, it's easy, since D3's longitude rotation equals trackball rotation around the vertical axis, and the subsequently applied latitude rotation