• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

2. Numbers and Dates > 2.8. Calculating Trigonometric Functions

Calculating Trigonometric Functions

NN 2, IE 3

Problem

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

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.

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.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint