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

Details

Syntax

acos(input)

Description

Returns the arccosine of a FLOAT in radians.

Arguments

Name

Type

Description

input

FLOAT

An angle in radians.

Returns

FLOAT

Considerations

acos(null) returns null.

If (input < -1) or (input > 1), then (acos(input)) returns NaN.

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

The arccosine of 0.5 is returned.

Result
acos(0.5)

1.0471975511965979

Rows: 1

asin()

Details

Syntax

asin(input)

Description

Returns the arcsine of a FLOAT in radians.

Arguments

Name

Type

Description

input

FLOAT

An angle in radians.

Returns

FLOAT

Considerations

asin(null) returns null.

If (input < -1) or (input > 1), then (asin(input)) returns NaN.

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

The arcsine of 0.5 is returned.

Result
asin(0.5)

0.5235987755982989

Rows: 1

atan()

Details

Syntax

atan(input)

Description

Returns the arctangent of a FLOAT in radians.

Arguments

Name

Type

Description

input

FLOAT

An angle in radians.

Returns

FLOAT

Considerations

atan(null) returns null.

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

The arctangent of 0.5 is returned.

Result
atan(0.5)

0.4636476090008061

Rows: 1

atan2()

Details

Syntax

atan2(y, x)

Description

Returns the arctangent2 of a set of coordinates in radians.

Arguments

Name

Type

Description

y

FLOAT

A y angle in radians.

x

FLOAT

An x angle in radians.

Returns

FLOAT

Considerations

atan2(null, null), atan2(null, x) and atan(y, null) all return null.

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

The arctangent2 of 0.5 and 0.6 is returned.

Result
atan2(0.5, 0.6)

0.6947382761967033

Rows: 1

cos()

Details

Syntax

cos(input)

Description

Returns the cosine of a FLOAT in radians.

Arguments

Name

Type

Description

input

FLOAT

An angle in radians.

Returns

FLOAT

Considerations

cos(null) returns null.

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

The cosine of 0.5 is returned.

Result
cos(0.5)

0.8775825618903728

Rows: 1

cot()

Details

Syntax

cot(input)

Description

Returns the cotangent of a FLOAT.

Arguments

Name

Type

Description

input

FLOAT

An angle in radians.

Returns

FLOAT

Considerations

cot(null) returns null.

cot(0) returns Infinity.

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

The cotangent of 0.5 is returned.

Result
cot(0.5)

1.830487721712452

Rows: 1

degrees()

Details

Syntax

degrees(input)

Description

Converts radians to degrees.

Arguments

Name

Type

Description

input

FLOAT

An angle in radians.

Returns

FLOAT

Considerations

degrees(null) returns null.

Example 7. degrees
Query
RETURN degrees(3.14159)

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

Result
degrees(3.14159)

179.9998479605043

Rows: 1

haversin()

Details

Syntax

haversin(input)

Description

Returns half the versine of a number.

Arguments

Name

Type

Description

input

FLOAT

An angle in radians.

Returns

FLOAT

Considerations

haversin(null) returns null.

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

The haversine of 0.5 is returned.

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.

Result
dist

9129.969740051658

Rows: 1

pi()

Details

Syntax

pi()

Description

Returns the mathematical constant pi.

Returns

FLOAT

Example 10. pi()
Query
RETURN pi()

The constant pi is returned.

Result
pi()

3.141592653589793

Rows: 1

radians()

Details

Syntax

radians(input)

Description

Converts degrees to radians.

Arguments

Name

Type

Description

input

FLOAT

An angle in degrees.

Returns

FLOAT

Considerations

radians(null) returns null.

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

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

Result
radians(180)

3.141592653589793

Rows: 1

sin()

Details

Syntax

sin(input)

Description

Returns the sine of a FLOAT.

Arguments

Name

Type

Description

input

FLOAT

An angle in radians.

Returns

FLOAT

Considerations

sin(null) returns null.

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

The sine of 0.5 is returned.

Result
sin(0.5)

0.479425538604203

Rows: 1

tan()

Details

Syntax

tan(input)

Description

Returns the tangent of a FLOAT.

Arguments

Name

Type

Description

input

FLOAT

An angle in radians.

Returns

FLOAT

Considerations

tan(null) returns null.

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

The tangent of 0.5 is returned.

Result
tan(0.5)

0.5463024898437905

Rows: 1