liveBook · Manning

Degrees

As explained in Math for Web Design

A degree is an angular measurement unit equal to one 360th of a full rotation.

A degree (°) measures rotation: one full circle is 360°. Angles describe how far one line, direction, or element turns from another. In interface work, degrees make rotations readable: `rotate(45deg)` turns an element 45 degrees clockwise, while a negative value turns it counterclockwise. section 1.4.7

CSS accepts several angle units. `deg` divides a circle into 360 parts; `rad` uses radians; `grad` divides a circle into 400 parts; and `turn` treats a full circle as `1turn`. Degree values wrap around a circle, so `360deg` equals `0deg`, `450deg` equals `90deg`, and `-90deg` equals `270deg`. section 9.1.2

Use degrees directly for visual rotation, but convert them when JavaScript trigonometry needs radians:

  • Convert degrees to radians with `radians = degrees * (Math.PI / 180)`. For example, 45° is `Math.PI / 4`. section 9.1.3
  • Convert radians to degrees with `degrees = radians * (180 / Math.PI)`. This is useful after `Math.atan2()` calculates a pointer direction. section 9.1.3
  • Use CSS degrees where the browser expects an angle, such as `element.style.transform = `rotate(${angle}deg)`;`. section 13.2.2
radians = degrees * (Math.PI / 180)
degrees = radians * (180 / Math.PI)

These paired formulas bridge CSS-friendly degree values and the radians required by JavaScript’s `Math.sin()`, `Math.cos()`, and `Math.atan2()`. section 9.1.3

Point a rotary control toward the cursor

A dial starts with mouse coordinates, finds the vector from its center to the pointer, and passes its vertical and horizontal distances to `Math.atan2()`. That result is radians, so convert it to degrees before using `rotate(...deg)`. A 90-degree adjustment can shift the reference from rightward—the usual zero-angle direction—to the top of a knob. section 13.2.2 section 13.4

Browser coordinates affect how degrees look on screen: x increases rightward and y increases downward. Thus 0° points right, 90° points down, and 45° points down and right. With a length and angle, cosine and sine turn that direction into x and y movement components. section 10.1

How Math for Web Design covers it

How deep it goes
Defines degree units, wraparound equivalents, and degree–radian conversion for CSS and JavaScript.
Examples
Uses a 135° conversion, CSS rotation, vector movement, and a mouse-driven volume dial.
What it assumes
Introduces degrees through basic angles and relates them directly to radians.
What you can do after
Apply it via CSS rotate() and JavaScript conversions for pointer-driven rotary controls.
How it connects
Connects degrees with radians, trigonometric functions, vectors, CSS transforms, 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.