Mathematical functions - trigonometric

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 1. Result
acos(0.5)

1.0471975511965979

1 row

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 2. Result
asin(0.5)

0.5235987755982989

1 row

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 3. Result
atan(0.5)

0.4636476090008061

1 row

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. Result
atan2(0.5, 0.6)

0.6947382761967033

1 row

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 5. Result
cos(0.5)

0.8775825618903728

1 row

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 6. Result
cot(0.5)

1.830487721712452

1 row

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 7. Result
degrees(3.14159)

179.99984796050427

1 row

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 8. Result
haversin(0.5)

0.06120871905481362

1 row

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

9129.969740051658

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

pi()

pi() returns the mathematical constant pi.

Syntax: pi()

Returns:

A Float.

Query
RETURN pi()

The constant pi is returned.

Table 10. Result
pi()

3.141592653589793

1 row

radians()

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 11. Result
radians(180)

3.141592653589793

1 row

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 12. Result
sin(0.5)

0.479425538604203

1 row

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 13. Result
tan(0.5)

0.5463024898437905

1 row