HTML and CSS Reference
In-Depth Information
Appendix
Useful Formulas
Throughout the topic, there are various formulas related to the different motions and effects you've
created. These have been distilled down to the most useful and most commonly used formulas, equations,
and code snippets, and are listed at the end of each chapter. These have been collected here to serve as
a one-shot reference for those things you'll probably use the most.
Chapter 3
Calculate basic trigonometric functions
sine of angle = opposite / hypotenuse
cosine of angle = adjacent / hypotenuse
tangent of angle = opposite / adjacent
Convert radians to degrees and degrees to radians
radians = degrees * Math.PI / 180
degrees = radians * 180 / Math.PI
Rotate to the mouse (or any point)
//substitute mouse.x, mouse.y with the x, y point to rotate to
dx = mouseX - object.x;
dy = mouseY - object.y;
object.rotation = Math.atan2(dy, dx) * 180 / Math.PI; //radians to degrees
 
Search WWH ::




Custom Search