9 Trigonometry for web developers
This chapter covers
- 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 to be useful in frontend web development. But modern browsers now offer tools that enable anyone to use 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, let’s first take a step back and understand a few fundamentals for implementing trigonometric calculations in frontend web development 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 defines a relationship between an angle θ (theta) and the ratios of the triangle’s sides: