9 Trigonometry for web developers
This chapter covers
- Learning the trig you need to know for web dev work
- Building circular layouts and animations
- Applying wave effects
- Making directional calculations
Trigonometry, the mathematics of angles and triangles, might seem too esoteric of a subject to be of use in frontend web development. However, modern browsers now offer tools that enable anyone to make use of trigonometric concepts to create rich visual effects, dynamic layouts, and smooth animations. From using CSS to rotate or skew elements to using JavaScript to animate elements along a curved path, trig stalwarts such as sine, cosine, and tangent make these and other frontend effects easier to implement and customize to your design requirements.
9.1 The basics of trigonometry for web design
Before the code starts flying, it will help to first take a step back to understand a few fundamentals for implementing trigonometric calculations in front end web dev work.
9.1.1 Sine, cosine, and tangent
Trigonometry is all about the relationships that exist within a triangle, particularly a right-angled triangle, where one of the angles is 90°, as shown in figure 9.1. The trig workhorses in frontend work are the three primary trig functions of sine (sin), cosine (cos), and tangent (tan), each of which defines a relationship between an angle θ (theta) and the ratios of the triangle’s sides: