## 4.7. Mathematical functions - trigonometric

These functions all operate on numeric expressions only, and will return an error if used on any other values. See also Section 2.7.4, “Mathematical operators”.

Functions:

### 4.7.1. acos()

`acos()` returns the arccosine of a number in radians.

Syntax: `acos(expression)`

Returns:

 A Float.

Arguments:

Name Description

`expression`

A numeric expression that represents the angle in radians.

Considerations:

 `acos(null)` returns `null`. If (`expression` < -1) or (`expression` > 1), then (`acos(expression)`) returns `null`.

Query.

``RETURN acos(0.5)``

The arccosine of `0.5` is returned.

Table 4.65. Result
acos(0.5)

1 row

`1.0471975511965979`

Try this query live.  none RETURN acos(0.5)

### 4.7.2. asin()

`asin()` returns the arcsine of a number in radians.

Syntax: `asin(expression)`

Returns:

 A Float.

Arguments:

Name Description

`expression`

A numeric expression that represents the angle in radians.

Considerations:

 `asin(null)` returns `null`. If (`expression` < -1) or (`expression` > 1), then (`asin(expression)`) returns `null`.

Query.

``RETURN asin(0.5)``

The arcsine of `0.5` is returned.

Table 4.66. Result
asin(0.5)

1 row

`0.5235987755982989`

Try this query live.  none RETURN asin(0.5)

### 4.7.3. atan()

`atan()` returns the arctangent of a number in radians.

Syntax: `atan(expression)`

Returns:

 A Float.

Arguments:

Name Description

`expression`

A numeric expression that represents the angle in radians.

Considerations:

 `atan(null)` returns `null`.

Query.

``RETURN atan(0.5)``

The arctangent of `0.5` is returned.

Table 4.67. Result
atan(0.5)

1 row

`0.4636476090008061`

Try this query live.  none RETURN atan(0.5)

### 4.7.4. atan2()

`atan2()` returns the arctangent2 of a set of coordinates in radians.

Syntax: `atan2(expression1, expression2)`

Returns:

 A Float.

Arguments:

Name Description

`expression1`

A numeric expression for y that represents the angle in radians.

`expression2`

A numeric expression for x that represents the angle in radians.

Considerations:

 `atan2(null, null)`, `atan2(null, expression2)` and `atan(expression1, null)` all return `null`.

Query.

``RETURN atan2(0.5, 0.6)``

The arctangent2 of `0.5` and `0.6` is returned.

Table 4.68. Result
atan2(0.5, 0.6)

1 row

`0.6947382761967033`

Try this query live.  none RETURN atan2(0.5, 0.6)

### 4.7.5. cos()

`cos()` returns the cosine of a number.

Syntax: `cos(expression)`

Returns:

 A Float.

Arguments:

Name Description

`expression`

A numeric expression that represents the angle in radians.

Considerations:

 `cos(null)` returns `null`.

Query.

``RETURN cos(0.5)``

The cosine of `0.5` is returned.

Table 4.69. Result
cos(0.5)

1 row

`0.8775825618903728`

Try this query live.  none RETURN cos(0.5)

### 4.7.6. cot()

`cot()` returns the cotangent of a number.

Syntax: `cot(expression)`

Returns:

 A Float.

Arguments:

Name Description

`expression`

A numeric expression that represents the angle in radians.

Considerations:

 `cot(null)` returns `null`. `cot(0)` returns `null`.

Query.

``RETURN cot(0.5)``

The cotangent of `0.5` is returned.

Table 4.70. Result
cot(0.5)

1 row

`1.830487721712452`

Try this query live.  none RETURN cot(0.5)

### 4.7.7. degrees()

`degrees()` converts radians to degrees.

Syntax: `degrees(expression)`

Returns:

 A Float.

Arguments:

Name Description

`expression`

A numeric expression that represents the angle in radians.

Considerations:

 `degrees(null)` returns `null`.

Query.

``RETURN degrees(3.14159)``

The number of degrees in something close to pi is returned.

Table 4.71. Result
degrees(3.14159)

1 row

`179.99984796050427`

Try this query live.  none RETURN degrees(3.14159)

### 4.7.8. haversin()

`haversin()` returns half the versine of a number.

Syntax: `haversin(expression)`

Returns:

 A Float.

Arguments:

Name Description

`expression`

A numeric expression that represents the angle in radians.

Considerations:

 `haversin(null)` returns `null`.

Query.

``RETURN haversin(0.5)``

The haversine of `0.5` is returned.

Table 4.72. Result
haversin(0.5)

1 row

`0.06120871905481362`

Try this query live.  none RETURN haversin(0.5)

### 4.7.9. Spherical distance using the `haversin()` function

The `haversin()` function may be used to compute the distance on the surface of a sphere between two points (each given by their latitude and longitude). In this example the spherical distance (in km) between Berlin in Germany (at lat 52.5, lon 13.4) and San Mateo in California (at lat 37.5, lon -122.3) is calculated using an average earth radius of 6371 km.

Query.

``````CREATE (ber:City { lat: 52.5, lon: 13.4 }),(sm:City { lat: 37.5, lon: -122.3 })
RETURN 2 * 6371 * asin(sqrt(haversin(radians(sm.lat - ber.lat))+ cos(radians(sm.lat))* cos(radians(ber.lat))* haversin(radians(sm.lon - ber.lon)))) AS dist``````

The estimated distance between 'Berlin' and 'San Mateo' is returned.

Table 4.73. Result
dist

1 row Nodes created: 2 Properties set: 4 Labels added: 2

`9129.969740051658`

Try this query live.  none CREATE (ber:City {lat: 52.5, lon: 13.4}), (sm:City {lat: 37.5, lon: -122.3}) RETURN 2 * 6371 * asin(sqrt(haversin(radians( sm.lat - ber.lat )) + cos(radians( sm.lat )) * cos(radians( ber.lat )) * haversin(radians( sm.lon - ber.lon )))) AS dist

### 4.7.10. pi()

`pi()` returns the mathematical constant pi.

Syntax: `pi()`

Returns:

 A Float.

Query.

``RETURN pi()``

The constant pi is returned.

Table 4.74. Result
pi()

1 row

`3.141592653589793`

Try this query live.  none RETURN pi()

`radians()` converts degrees to radians.

Syntax: `radians(expression)`

Returns:

 A Float.

Arguments:

Name Description

`expression`

A numeric expression that represents the angle in degrees.

Considerations:

 `radians(null)` returns `null`.

Query.

``RETURN radians(180)``

The number of radians in `180` degrees is returned (pi).

Table 4.75. Result

1 row

`3.141592653589793`

Try this query live.  none RETURN radians(180)

### 4.7.12. sin()

`sin()` returns the sine of a number.

Syntax: `sin(expression)`

Returns:

 A Float.

Arguments:

Name Description

`expression`

A numeric expression that represents the angle in radians.

Considerations:

 `sin(null)` returns `null`.

Query.

``RETURN sin(0.5)``

The sine of `0.5` is returned.

Table 4.76. Result
sin(0.5)

1 row

`0.479425538604203`

Try this query live.  none RETURN sin(0.5)

### 4.7.13. tan()

`tan()` returns the tangent of a number.

Syntax: `tan(expression)`

Returns:

 A Float.

Arguments:

Name Description

`expression`

A numeric expression that represents the angle in radians.

Considerations:

 `tan(null)` returns `null`.

Query.

``RETURN tan(0.5)``

The tangent of `0.5` is returned.

Table 4.77. Result
tan(0.5)

1 row

`0.5463024898437905`

Try this query live.  none RETURN tan(0.5)