acos()#
relationalai.std.math
#acos(number: Number|Producer) -> Expression
Calculates the inverse cosine (arccosine) of number
, where number
is specified in radians and must be in the range -1
to 1
.
If number
is a Producer
, acos()
filters out any non-number or invalid values from the producer.
Must be called in a rule or query context.
Parameters#
Name | Type | Description |
---|---|---|
number | Producer or Python Number object | The value to calculate the arccosine of, in the range -1 to 1 . |
Returns#
An Expression
object.
Example#
Use acos()
to calculate the arccosine of a value in radians:
#import relationalai as rai
from relationalai.std import math
# =====
# SETUP
# =====
model = rai.Model("MyModel")
Satellite = model.Type("Satellite")
with model.rule():
Satellite.add(id=1).set(name="SatA", orientation=0.5)
Satellite.add(id=2).set(name="SatB", orientation=1.0)
Satellite.add(id=3).set(name="SatC", orientation=-1.5) # Out of range
Satellite.add(id=4).set(name="SatD", orientation="INVALID") # Non-numeric value
# =======
# EXAMPLE
# =======
# Set an orientation_acos property to the arccosine of each satellite's orientation.
with model.rule():
satellite = Satellite()
satellite.set(orientation_acos=math.acos(satellite.orientation))
# Since acos() filters out non-numeric or out-of-range values, the orientation_acos
# property is not set for satellites with IDs 3 and 4.
with model.query() as select:
satellite = Satellite()
response = select(satellite.id, satellite.name, satellite.orientation_acos)
print(response.results)
# id name orientation_acos
# 0 1 SatA 1.047198
# 1 2 SatB 0.000000
# 2 3 SatC NaN
# 3 4 SatD NaN