AGE provides the following trigonometric functions for use in Cypher queries. All functions accept agtype numeric expressions and return an agtype floating-point number.
Function overview
| Function | Signature | Description |
|---|---|---|
degrees | degrees(expression) | Converts an angle from radians to degrees. |
radians | radians(expression) | Converts an angle from degrees to radians. |
pi | pi() | Returns the mathematical constant π (approximately 3.14159265358979). |
sin | sin(expression) | Returns the sine of an angle in radians. |
cos | cos(expression) | Returns the cosine of an angle in radians. |
tan | tan(expression) | Returns the tangent of an angle in radians. |
cot | cot(expression) | Returns the cotangent of an angle in radians. |
asin | asin(expression) | Returns the arcsine of a value in [-1, 1], in radians. |
acos | acos(expression) | Returns the arccosine of a value in [-1, 1], in radians. |
atan | atan(expression) | Returns the arctangent of a number, in radians. |
atan2 | atan2(expression1, expression2) | Returns the arctangent of the point (x, y), in radians. |
degrees
Converts an angle from radians to degrees.
Syntax
degrees(expression)Parameters
| Parameter | Type | Description |
|---|---|---|
expression | agtype number | The angle in radians. |
Returns
agtype floating-point number.
Usage notes
degrees(null) returns null.
Example
SELECT *
FROM cypher('graph_name', $$
RETURN degrees(3.14159)
$$) as (deg agtype);The angle close to π radians is converted to degrees:
deg
------------------
179.999847960504
(1 row)radians
Converts an angle from degrees to radians.
Syntax
radians(expression)Parameters
| Parameter | Type | Description |
|---|---|---|
expression | agtype number | The angle in degrees. |
Returns
agtype floating-point number.
Usage notes
radians(null) returns null.
Example
SELECT *
FROM cypher('graph_name', $$
RETURN radians(180)
$$) as (rad agtype);180 degrees is converted to the radian value of π:
rad
------------------
3.14159265358979
(1 row)pi
Returns the mathematical constant π.
Syntax
pi()Parameters
None.
Returns
agtype floating-point number.
Example
SELECT *
FROM cypher('graph_name', $$
RETURN pi()
$$) as (p agtype); p
------------------
3.14159265358979
(1 row)sin
Returns the sine of an angle.
Syntax
sin(expression)Parameters
| Parameter | Type | Description |
|---|---|---|
expression | agtype number | The angle in radians. |
Returns
agtype floating-point number.
Usage notes
sin(null) returns null.
Example
SELECT *
FROM cypher('graph_name', $$
RETURN sin(0.5)
$$) as (s agtype); s
-------------------
0.479425538604203
(1 row)cos
Returns the cosine of an angle.
Syntax
cos(expression)Parameters
| Parameter | Type | Description |
|---|---|---|
expression | agtype number | The angle in radians. |
Returns
agtype floating-point number.
Usage notes
cos(null) returns null.
Example
SELECT *
FROM cypher('graph_name', $$
RETURN cos(0.5)
$$) as (c agtype); c
-------------------
0.877582561890373
(1 row)tan
Returns the tangent of an angle.
Syntax
tan(expression)Parameters
| Parameter | Type | Description |
|---|---|---|
expression | agtype number | The angle in radians. |
Returns
agtype floating-point number.
Usage notes
tan(null) returns null.
Example
SELECT *
FROM cypher('graph_name', $$
RETURN tan(0.5)
$$) as (t agtype); t
------------------
0.54630248984379
(1 row)cot
Returns the cotangent of an angle.
Syntax
cot(expression)Parameters
| Parameter | Type | Description |
|---|---|---|
expression | agtype number | The angle in radians. |
Returns
agtype floating-point number.
Usage notes
cot(null) returns null.
Example
SELECT *
FROM cypher('graph_name', $$
RETURN cot(0.5)
$$) as (t agtype); t
------------------
1.83048772171245
(1 row)asin
Returns the arcsine of a number. The input must be in the range [-1, 1].
Syntax
asin(expression)Parameters
| Parameter | Type | Description |
|---|---|---|
expression | agtype number | An agtype number expression that represents the angle in radians. |
Returns
agtype floating-point number.
Usage notes
asin(null)returnsnull.If
expression < -1orexpression > 1,asin(expression)returnsnull.
Example
SELECT *
FROM cypher('graph_name', $$
RETURN asin(0.5)
$$) as (arc_s agtype); arc_s
-------------------
0.523598775598299
(1 row)acos
Returns the arccosine of a number. The input must be in the range [-1, 1].
Syntax
acos(expression)Parameters
| Parameter | Type | Description |
|---|---|---|
expression | agtype number | An agtype number expression that represents the angle in radians. |
Returns
agtype floating-point number.
Usage notes
acos(null)returnsnull.If
expression < -1orexpression > 1,acos(expression)returnsnull.
Example
SELECT *
FROM cypher('graph_name', $$
RETURN acos(0.5)
$$) as (arc_c agtype); arc_c
-----------------
1.0471975511966
(1 row)atan
Returns the arctangent of a number.
Syntax
atan(expression)Parameters
| Parameter | Type | Description |
|---|---|---|
expression | agtype number | The angle in radians. |
Returns
agtype floating-point number.
Usage notes
atan(null) returns null.
Example
SELECT *
FROM cypher('graph_name', $$
RETURN atan(0.5)
$$) as (arc_t agtype); arc_t
-------------------
0.463647609000806
(1 row)atan2
Returns the arctangent of the point (x, y) in radians. Unlike atan, this function takes two arguments to determine the correct quadrant of the result.
Syntax
atan2(expression1, expression2)Parameters
| Parameter | Type | Description |
|---|---|---|
expression1 | agtype number | An agtype number expression for y that represents the angle in radians. |
expression2 | agtype number | An agtype number expression for x that represents the angle in radians. |
Returns
agtype floating-point number.
Usage notes
atan2(null, null), atan2(null, expression2), and atan2(expression1, null) return null.
Example
SELECT *
FROM cypher('graph_name', $$
RETURN atan2(0.5, 0.6)
$$) as (arc_t2 agtype); arc_t2
-------------------
0.694738276196703
(1 row)