Mathematical functions - trigonometric

Trigonometric mathematical functions operate on numeric expressions only, and will return an error if used on any other values. See also Mathematical operators.

acos()

acos() returns the arccosine of a FLOAT in radians.

Syntax:

acos(expression)

Returns:

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 NaN.

Example 1. acos()
Query
RETURN acos(0.5)

The arccosine of 0.5 is returned.

Table 1. Result
acos(0.5)

1.0471975511965979

Rows: 1

asin()

asin() returns the arcsine of a FLOAT in radians.

Syntax:

asin(expression)

Returns:

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 NaN.

Example 2. asin()
Query
RETURN asin(0.5)

The arcsine of 0.5 is returned.

Table 2. Result
asin(0.5)

0.5235987755982989

Rows: 1

atan()

atan() returns the arctangent of a FLOAT in radians.

Syntax:

atan(expression)

Returns:

FLOAT

Arguments:

Name Description

expression

A numeric expression that represents the angle in radians.

Considerations:

atan(null) returns null.

Example 3. atan()
Query
RETURN atan(0.5)

The arctangent of 0.5 is returned.

Table 3. Result
atan(0.5)

0.4636476090008061

Rows: 1

atan2()

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

Syntax:

atan2(expression1, expression2)

Returns:

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.

Example 4. atan2()
Query
RETURN atan2(0.5, 0.6)

The arctangent2 of 0.5 and 0.6 is returned.

Table 4. Result
atan2(0.5, 0.6)

0.6947382761967033

Rows: 1

cos()

cos() returns the cosine of a FLOAT.

Syntax:

cos(expression)

Returns:

FLOAT

Arguments:

Name Description

expression

A numeric expression that represents the angle in radians.

Considerations:

cos(null) returns null.

Example 5. cos()
Query
RETURN cos(0.5)

The cosine of 0.5 is returned.

Table 5. Result
cos(0.5)

0.8775825618903728

Rows: 1

cot()

cot() returns the cotangent of a FLOAT.

Syntax:

cot(expression)

Returns:

FLOAT

Arguments:

Name Description

expression

A numeric expression that represents the angle in radians.

Considerations:

cot(null) returns null.

cot(0) returns Infinity.

Example 6. cot()
Query
RETURN cot(0.5)

The cotangent of 0.5 is returned.

Table 6. Result
cot(0.5)

1.830487721712452

Rows: 1

degrees()

degrees() converts radians to degrees.

Syntax:

degrees(expression)

Returns:

FLOAT

Arguments:

Name Description

expression

A numeric expression that represents the angle in radians.

Considerations:

degrees(null) returns null.

Example 7. degrees
Query
RETURN degrees(3.14159)

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

Table 7. Result
degrees(3.14159)

179.9998479605043

Rows: 1

haversin()

haversin() returns half the versine of a number.

Syntax:

haversin(expression)

Returns:

FLOAT

Arguments:

Name Description

expression

A numeric expression that represents the angle in radians.

Considerations:

haversin(null) returns null.

Example 8. haversin()
Query
RETURN haversin(0.5)

The haversine of 0.5 is returned.

Table 8. Result
haversin(0.5)

0.06120871905481362

Rows: 1

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).

Example 9. haversin()

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 9. Result
dist

9129.969740051658

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

pi()

pi() returns the mathematical constant pi.

Syntax:

pi()

Returns:

FLOAT

Example 10. pi()
Query
RETURN pi()

The constant pi is returned.

Table 10. Result
pi()

3.141592653589793

Rows: 1

radians()

radians() converts degrees to radians.

Syntax:

radians(expression)

Returns:

FLOAT

Arguments:

Name Description

expression

A numeric expression that represents the angle in degrees.

Considerations:

radians(null) returns null.

Example 11. radians()
Query
RETURN radians(180)

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

Table 11. Result
radians(180)

3.141592653589793

Rows: 1

sin()

sin() returns the sine of a number.

Syntax:

sin(expression)

Returns:

FLOAT

Arguments:

Name Description

expression

A numeric expression that represents the angle in radians.

Considerations:

sin(null) returns null.

Example 12. sin()
Query
RETURN sin(0.5)

The sine of 0.5 is returned.

Table 12. Result
sin(0.5)

0.479425538604203

Rows: 1

tan()

tan() returns the tangent of a number.

Syntax:

tan(expression)

Returns:

FLOAT

Arguments:

Name Description

expression

A numeric expression that represents the angle in radians.

Considerations:

tan(null) returns null.

Example 13. tan()
Query
RETURN tan(0.5)

The tangent of 0.5 is returned.

Table 13. Result
tan(0.5)

0.5463024898437905

Rows: 1