liveBook · Manning

Trigonometry

As explained in D3.js in Action, Third Edition

Trigonometry is the branch of mathematics that relates angles to lengths and coordinates in geometric figures.

Trigonometry relates angles to positions and lengths. In a radial visualization, it converts each month’s angle and circle radius into the endpoint of an SVG axis. section 14.5.1

For an axis forming a right-angled triangle:

  • Calculate the horizontal coordinate with x = radius × sin(θ). section 14.5.1
  • Calculate the vertical coordinate with y = −radius × cos(θ), accounting for SVG’s vertical direction. section 14.5.1
  • Map twelve months across 0 to 2π − 2π/12 radians so January sits at twelve o’clock. section 14.5.1

Radial month axes

A Svelte component uses d3-scale’s point scale for month angles, then assigns each SVG line an origin of (0, 0) and sine/cosine-derived endpoints.

How D3.js in Action, Third Edition covers it

How deep it goes
Derives sine and cosine coordinates from a right triangle, then applies radians and coordinate-system direction in code.
Examples
Uses a twelve-month radial chart with a circle, month axes, labels, radius, and a centered SVG coordinate system.
What you can do after
Build it from scratch by calculating radial SVG endpoints from angles, radii, sine, and cosine.
How it connects
Connects right-angled triangles, sine, cosine, radians, SVG coordinates, and point scales.

Also explained in

Compare how 2 books explain trigonometry →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of D3.js in Action, Third Edition. The section links point to the parts of the book it draws on.