degrees()#
relationalai.std.math
#degrees(radians: Number|Producer) -> Expression
Converts an angle from radians to degrees.
If radians
is a Producer
, degrees()
filters out any non-numeric values from the producer.
Must be called in a rule or query context.
Parameters#
Name | Type | Description |
---|---|---|
radians | Producer or Python Number object | The angle in radians to convert to degrees. |
Returns#
An Expression
object.
Example#
Use degrees()
to convert an angle from radians to degrees:
#import relationalai as rai
from relationalai.std import math
# =====
# SETUP
# =====
model = rai.Model("MyModel")
Angle = model.Type("Angle")
with model.rule():
Angle.add(id=1).set(radians=1.570796) # Approximately π/2
Angle.add(id=2).set(radians=3.141593) # Approximately π
Angle.add(id=3).set(radians="INVALID") # Non-numeric value
# =======
# EXAMPLE
# =======
# Set a degrees property to the degrees equivalent of each angle's radians value.
with model.rule():
angle = Angle()
angle.set(degrees=math.degrees(angle.radians))
# Since degrees() filters out non-numeric values, the degrees_value property
# is not set for the angle with id=3.
with model.query() as select:
angle = Angle()
response = select(angle.id, angle.degrees)
print(response.results)
# id degrees
# 0 1 89.999981
# 1 2 180.000020
# 2 3 NaN