liveBook · Manning

Direction

As explained in Math for Web Design

Direction is the orientation of a vector, commonly expressed as an angle relative to a reference axis.

Direction describes the orientation of movement relative to a reference axis. In UI work, a vector pairs direction with distance: [x, y] means how far an element moves horizontally and vertically. With browser coordinates, x increases rightward and y increases downward, so adding [50, 20] to (100, 100) produces (150, 120). section 10.1

Use direction calculations to connect geometry with interface behavior:

  • Represent a displacement as an [x, y] vector rather than an unspecified movement. section 10.1
  • Find the direction between two points with Math.atan2(), after measuring their coordinate differences. section 13.5

Pointer direction in a gesture

Read event.clientX and event.clientY relative to the viewport, convert them to an element’s local coordinates by subtracting its bounding-rectangle offsets, then use Math.atan2() to determine the pointer’s direction. The resulting angle can drive a slider, animation, or other interactive response. section 13.5

How Math for Web Design covers it

How deep it goes
Works from two-dimensional coordinates and vectors through applied pointer calculations with Math.atan2().
Examples
Uses vector offsets, angle-to-component calculations, and pointer coordinates for gesture interaction.
What it assumes
Assumes basic two-dimensional coordinates while defining vectors and browser positions from those foundations.
What you can do after
Apply it via JavaScript to derive movement components and pointer direction for interactive UI behavior.
How it connects
Connects points, vectors, coordinates, distance, and Math.atan2().

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math for Web Design. The section links point to the parts of the book it draws on.