web.dev

Trigonometric functions in CSS

thumbnail
  1. Introduction to Trigonometric Functions in CSS
  • CSS now supports trigonometric functions such as sin, cos, and tan
  • These functions can be used to calculate angles and positions in CSS
  • This article demonstrates how to use these functions to draw shapes and position elements
  1. Drawing Shapes with Trigonometric Functions
  • The sin and cos functions can be used to draw lines and shapes
  • Example: drawing a triangle using sin and cos to calculate the positions of each point
  1. Using Inverse Trigonometric Functions
  • CSS also supports inverse trigonometric functions such as asin, acos, and atan
  • These functions can be used to calculate angles from a given position
  • Example: using atan to calculate the angle between two points
  1. Rotating Elements to Face a Point
  • The atan2 function can be used to calculate the relative angle between two points
  • This angle can be used to rotate elements so that they face each other
  • Example: using atan2 to rotate boxes to face the location of the mouse