Trigonometric Functions in PHP

Author — Nitish Kumar

On This Page
  1. PHP sin() Function
    1. PHP sin() Usage
    2. PHP sin() Syntax
    3. PHP sin() Parameters
    4. PHP sin() Return Value
    5. PHP sin() Working Examples
      1. 1. sin() example
  2. PHP cos() Function
    1. PHP cos() Usage
    2. PHP cos() Syntax
    3. PHP cos() Parameters
    4. PHP cos() Return Value
    5. PHP cos() Working Examples
      1. 1. cos() example
  3. PHP tan() Function
    1. PHP tan() Usage
    2. PHP tan() Syntax
    3. PHP tan() Parameters
    4. PHP tan() Return Value
    5. PHP tan() Working Examples
      1. 1. tan() example
  4. PHP asin() Function
    1. PHP asin() Usage
    2. PHP asin() Syntax
    3. PHP asin() Parameters
    4. PHP asin() Return Value
  5. PHP acos() Function
    1. PHP acos() Usage
    2. PHP acos() Syntax
    3. PHP acos() Parameters
    4. PHP acos() Return Value
  6. PHP atan() Function
    1. PHP atan() Usage
    2. PHP atan() Syntax
    3. PHP atan() Parameters
    4. PHP atan() Return Value
    5. Additional Tips from Fellow Developers
  7. PHP atan2() Function
    1. PHP atan2() Usage
    2. PHP atan2() Syntax
    3. PHP atan2() Parameters
    4. PHP atan2() Return Value
    5. Additional Tips from Fellow Developers
  8. PHP asinh() Function
    1. PHP asinh() Usage
    2. PHP asinh() Syntax
    3. PHP asinh() Parameters
    4. PHP asinh() Return Value
    5. Changelog for PHP asinh() Function
  9. PHP acosh() Function
    1. PHP acosh() Usage
    2. PHP acosh() Syntax
    3. PHP acosh() Parameters
    4. PHP acosh() Return Value
    5. Changelog for PHP acosh() Function
  10. PHP atanh() Function
    1. PHP atanh() Usage
    2. PHP atanh() Syntax
    3. PHP atanh() Parameters
    4. PHP atanh() Return Value
    5. Changelog for PHP atanh() Function
  11. PHP deg2rad() Function
    1. PHP deg2rad() Usage
    2. PHP deg2rad() Syntax
    3. PHP deg2rad() Parameters
    4. PHP deg2rad() Return Value
    5. PHP deg2rad() Working Examples
      1. 1. deg2rad() example
  12. PHP rad2deg() Function
    1. PHP rad2deg() Usage
    2. PHP rad2deg() Syntax
    3. PHP rad2deg() Parameters
    4. PHP rad2deg() Return Value
    5. PHP rad2deg() Working Examples
      1. 1. rad2deg() example

PHP sin() Function

PHP sin() Usage

The PHP sin() function will give you the sine of the arg parameter. The arg parameter is in radians.

PHP sin() Syntax

 sin ( float $arg ) : float

PHP sin() Parameters

  1. arg — A value in radians

PHP sin() Return Value

The PHP sin() function returns the sine of arg

PHP sin() Working Examples

1. sin() example

<?php
// Precision depends on your precision directive
echo sin(deg2rad(60));  //  0.866025403 ...
echo sin(60);           // -0.304810621 ...
?>

PHP cos() Function

PHP cos() Usage

The PHP cos() function will give you the cosine of the arg parameter. The arg parameter is in radians.

PHP cos() Syntax

 cos ( float $arg ) : float

PHP cos() Parameters

  1. arg — An angle in radians

PHP cos() Return Value

The PHP cos() function returns the cosine of arg

PHP cos() Working Examples

1. cos() example

<?php
echo cos(M_PI); // -1
?>

PHP tan() Function

PHP tan() Usage

The PHP tan() function will give you the tangent of the arg parameter. The arg parameter is in radians.

PHP tan() Syntax

 tan ( float $arg ) : float

PHP tan() Parameters

  1. arg — The argument to process in radians

PHP tan() Return Value

The PHP tan() function returns the tangent of arg

PHP tan() Working Examples

1. tan() example

<?php
echo tan(M_PI_4); // 1
?>

PHP asin() Function

PHP asin() Usage

The PHP asin() function will give you the arc sine of arg in radians. asin() is the inverse function of sin(), which means that a==sin(asin(a)) for every value of a that is within asin()‘s range.

PHP asin() Syntax

 asin ( float $arg ) : float

PHP asin() Parameters

  1. arg — The argument to process

PHP asin() Return Value

The PHP asin() function returns the arc sine of arg in radians

PHP acos() Function

PHP acos() Usage

The PHP acos() function will give you the arc cosine of arg in radians. acos() is the inverse function of cos(), which means that a==cos(acos(a)) for every value of a that is within acos()‘ range.

PHP acos() Syntax

 acos ( float $arg ) : float

PHP acos() Parameters

  1. arg — The argument to process

PHP acos() Return Value

The PHP acos() function returns the arc cosine of arg in radians.

PHP atan() Function

PHP atan() Usage

The PHP atan() function will give you the arc tangent of arg in radians. atan() is the inverse function of tan(), which means that a==tan(atan(a)) for every value of a that is within atan()‘s range.

PHP atan() Syntax

 atan ( float $arg ) : float

PHP atan() Parameters

  1. arg — The argument to process

PHP atan() Return Value

The PHP atan() function returns the arc tangent of arg in radians.

Additional Tips from Fellow Developers

Contributed By: Anonymous

Contrary to the current description, it should hold y == tan(atan(y)) for ALL  y.
However, x == atan(tan(x)) only holds for those x which are in the range of atan, which are those x with -pi/2 < x < pi/2.
Of course, those equalities are limited by precision. On my machine
tan(atan(1000)) returns 1000.0000000001.
atan(tan(0)) returns 0 (correct).
atan(tan(M_PI)) returns -1.2246467991474E-16 instead of 0.

PHP atan2() Function

PHP atan2() Usage

The PHP atan2() function will this function calculates the arc tangent of the two variables x and y. It is similar to calculating the arc tangent of y / x, except that the signs of both arguments are used to determine the quadrant of the result.

PHP atan2() Syntax

 atan2 ( float $y , float $x ) : float

PHP atan2() Parameters

  1. y — Dividend parameter

  2. x — Divisor parameter

PHP atan2() Return Value

The PHP atan2() function returns the arc tangent of y/x in radians.

Additional Tips from Fellow Developers

Contributed By: reubs

Just a note:
PHP's atan2 function receives parameters in (y,x) and Excel receives it in (x,y) format. Just in case you are porting formulas across. :)

PHP asinh() Function

PHP asinh() Usage

The PHP asinh() function will give you the inverse hyperbolic sine of arg, i.e. the value whose hyperbolic sine is arg.

PHP asinh() Syntax

 asinh ( float $arg ) : float

PHP asinh() Parameters

  1. arg — The argument to process

PHP asinh() Return Value

The PHP asinh() function returns the inverse hyperbolic sine of arg

Changelog for PHP asinh() Function

5.3.0 — This function is now available on all platforms

PHP acosh() Function

PHP acosh() Usage

The PHP acosh() function will give you the inverse hyperbolic cosine of arg, i.e. the value whose hyperbolic cosine is arg.

PHP acosh() Syntax

 acosh ( float $arg ) : float

PHP acosh() Parameters

  1. arg — The value to process

PHP acosh() Return Value

The PHP acosh() function returns the inverse hyperbolic cosine of arg

Changelog for PHP acosh() Function

5.3.0 — This function is now available on all platforms

PHP atanh() Function

PHP atanh() Usage

The PHP atanh() function will give you the inverse hyperbolic tangent of arg, i.e. the value whose hyperbolic tangent is arg.

PHP atanh() Syntax

 atanh ( float $arg ) : float

PHP atanh() Parameters

  1. arg — The argument to process

PHP atanh() Return Value

The PHP atanh() function returns inverse hyperbolic tangent of arg

Changelog for PHP atanh() Function

5.3.0 — This function is now available on all platforms

PHP deg2rad() Function

PHP deg2rad() Usage

The PHP deg2rad() function will converts the number in degrees to the radian equivalent .

PHP deg2rad() Syntax

 deg2rad ( float $number ) : float

PHP deg2rad() Parameters

  1. number — Angular value in degrees

PHP deg2rad() Return Value

The PHP deg2rad() function returns the radian equivalent of number

PHP deg2rad() Working Examples

1. deg2rad() example

<?php
echo deg2rad(45); // 0.785398163397
var_dump(deg2rad(45) === M_PI_4); // bool(true)
?>

PHP rad2deg() Function

PHP rad2deg() Usage

The PHP rad2deg() function will converts the radian number to the equivalent number in degrees .

PHP rad2deg() Syntax

 rad2deg ( float $number ) : float

PHP rad2deg() Parameters

  1. number — A radian value

PHP rad2deg() Return Value

The PHP rad2deg() function returns the equivalent of number in degrees

PHP rad2deg() Working Examples

1. rad2deg() example

<?php
echo rad2deg(M_PI_4); // 45
?>


Rate this post —

Very PoorPoorAverageGoodExcellent (1 votes, average: 5.00 out of 5)
Loading...
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0%