# 2.8 Calculating Trigonometric Functions

NN 2, IE 3

#### 2.8.1 Problem

You want to invoke a variety of trigonometric functions, perhaps for calculating animation paths of a positioned element.

#### 2.8.2 Solution

JavaScript's Math object comes with a typical complement of functions for trigonometric calculations. Each one requires one or two arguments and returns a result in radians. Arguments representing angles must also be expressed in radians. The following statement assigns the sine of a value to a variable:

`var sineValue = Math.sin(radiansInput);`

All Math object methods must be invoked as methods of the static Math object.

#### 2.8.3 Discussion

See the introduction to this chapter for a summary of all Math object methods and constants. You can see an application of trigonometric functions in Recipe 13.10, which calculates the circular path for a positioned element to follow on the page.

#### 2.8.4 See Also

Section 2.0.2 in the introduction of this chapter; Recipe 13.10 where some trigonometric operations help calculate points around a circular path.  Chapter 1. Strings  Chapter 2. Numbers and Dates  2.0 Introduction  2.1 Converting Between Numbers and Strings  2.2 Testing a Number's Validity  2.3 Testing Numeric Equality  2.4 Rounding Floating-Point Numbers  2.5 Formatting Numbers for Text Display  2.6 Converting Between Decimal and Hexadecimal Numbers  2.7 Generating Pseudorandom Numbers  2.8 Calculating Trigonometric Functions  2.9 Creating a Date Object  2.10 Calculating a Previous or Future Date  2.11 Calculating the Number of Days Between Two Dates  2.12 Validating a Date  Chapter 3. Arrays and Objects  Chapter 4. Variables, Functions, and Flow Control  Chapter 5. Browser Feature Detection  Chapter 6. Managing Browser Windows  Chapter 7. Managing Multiple Frames  Chapter 8. Dynamic Forms  Chapter 9. Managing Events  Chapter 10. Page Navigation Techniques  Chapter 11. Managing Style Sheets  Chapter 12. Visual Effects for Stationary Content  Chapter 13. Positioning HTML Elements  Chapter 14. Creating Dynamic Content  Chapter 15. Dynamic Content Applications  Appendix A. Keyboard Event Character Values  Appendix B. Keyboard Key Code Values  Appendix C. ECMAScript Reserved Keywords