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()
Syntax |
|
||
Description |
Returns the arccosine of a |
||
Arguments |
Name |
Type |
Description |
|
|
An angle in radians. |
|
Returns |
|
|
If ( |
RETURN acos(0.5)
The arccosine of 0.5
is returned.
acos(0.5) |
---|
|
Rows: 1 |
asin()
Syntax |
|
||
Description |
Returns the arcsine of a |
||
Arguments |
Name |
Type |
Description |
|
|
An angle in radians. |
|
Returns |
|
|
If ( |
RETURN asin(0.5)
The arcsine of 0.5
is returned.
asin(0.5) |
---|
|
Rows: 1 |
atan()
Syntax |
|
||
Description |
Returns the arctangent of a |
||
Arguments |
Name |
Type |
Description |
|
|
An angle in radians. |
|
Returns |
|
|
RETURN atan(0.5)
The arctangent of 0.5
is returned.
atan(0.5) |
---|
|
Rows: 1 |
atan2()
Syntax |
|
||
Description |
Returns the arctangent2 of a set of coordinates in radians. |
||
Arguments |
Name |
Type |
Description |
|
|
A y angle in radians. |
|
|
|
An x angle in radians. |
|
Returns |
|
|
RETURN atan2(0.5, 0.6)
The arctangent2 of 0.5
and 0.6
is returned.
atan2(0.5, 0.6) |
---|
|
Rows: 1 |
cos()
Syntax |
|
||
Description |
Returns the cosine of a |
||
Arguments |
Name |
Type |
Description |
|
|
An angle in radians. |
|
Returns |
|
|
RETURN cos(0.5)
The cosine of 0.5
is returned.
cos(0.5) |
---|
|
Rows: 1 |
cot()
Syntax |
|
||
Description |
Returns the cotangent of a |
||
Arguments |
Name |
Type |
Description |
|
|
An angle in radians. |
|
Returns |
|
|
|
RETURN cot(0.5)
The cotangent of 0.5
is returned.
cot(0.5) |
---|
|
Rows: 1 |
degrees()
Syntax |
|
||
Description |
Converts radians to degrees. |
||
Arguments |
Name |
Type |
Description |
|
|
An angle in radians. |
|
Returns |
|
|
RETURN degrees(3.14159)
The number of degrees in something close to pi is returned.
degrees(3.14159) |
---|
|
Rows: 1 |
haversin()
Syntax |
|
||
Description |
Returns half the versine of a number. |
||
Arguments |
Name |
Type |
Description |
|
|
An angle in radians. |
|
Returns |
|
|
RETURN haversin(0.5)
The haversine of 0.5
is returned.
haversin(0.5) |
---|
|
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).
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.
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.
dist |
---|
|
Rows: 1 |
pi()
Syntax |
|
||
Description |
Returns the mathematical constant pi. |
||
Returns |
|
RETURN pi()
The constant pi is returned.
pi() |
---|
|
Rows: 1 |
radians()
Syntax |
|
||
Description |
Converts degrees to radians. |
||
Arguments |
Name |
Type |
Description |
|
|
An angle in degrees. |
|
Returns |
|
|
RETURN radians(180)
The number of radians in 180
degrees is returned (pi).
radians(180) |
---|
|
Rows: 1 |
sin()
Syntax |
|
||
Description |
Returns the sine of a |
||
Arguments |
Name |
Type |
Description |
|
|
An angle in radians. |
|
Returns |
|
|
RETURN sin(0.5)
The sine of 0.5
is returned.
sin(0.5) |
---|
|
Rows: 1 |
tan()
Syntax |
|
||
Description |
Returns the tangent of a |
||
Arguments |
Name |
Type |
Description |
|
|
An angle in radians. |
|
Returns |
|
|
RETURN tan(0.5)
The tangent of 0.5
is returned.
tan(0.5) |
---|
|
Rows: 1 |