liveBook · Manning

Sine function

As explained in D3.js in Action, Third Edition

Sine is a trigonometric function that gives the ratio of the opposite side to the hypotenuse in a right triangle.

The sine of an angle in a right triangle is the opposite-side length divided by the hypotenuse. In a circular visualization, multiply the radius by sin(θ) to find an axis endpoint’s horizontal position. section 14.5.1

Use sine when positioning radial elements:

  • Represent each month with an angle from 0 to nearly 2π using a point scale. section 14.5.1
  • Set an SVG line’s horizontal endpoint to radius × sin(angle). section 14.5.1
  • Pair sine with cosine for the vertical endpoint, reversing its sign for SVG’s downward y-axis. section 14.5.1

Month axes in a radial chart

For each month, draw an SVG line from (0, 0) to (radius × Math.sin(monthScale(month)), −radius × Math.cos(monthScale(month))). January begins at twelve o’clock.

How D3.js in Action, Third Edition covers it

How deep it goes
Explains the right-triangle ratio and applies it in Svelte code, without developing broader trigonometric theory.
Examples
Uses February’s axis and twelve month axes as concrete radial-chart examples.
What it assumes
Builds right-triangle trigonometry from a basic angle, radius, and coordinate-system setup.
What you can do after
Build it from scratch by calculating and rendering radial SVG endpoints from angles and a radius.
How it connects
Connects sine with cosine, right triangles, angles, radians, SVG coordinates, and point scales.

Also explained in

Compare how 3 books explain sine function →

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.