文档菜单
文档首页
/
MongoDB 手册
/ / /

$atan (聚合)

本页

  • 行为
  • 示例
$atan

返回值的反正切(反正切)。

$atan 有以下语法

{ $atan: <expression> }

$atan 接受任何有效的表达式,该表达式解析为数字。

$atan 返回弧度值。使用 $radiansToDegrees 运算符将输出值从弧度转换为度。

默认情况下,$atan 返回值为 double 类型。只要 <expression> 解析为 128 位十进制值,$atan 也可以返回 128 位十进制 值。

有关表达式更多信息,请参阅 表达式运算符。

如果参数解析为 null 或引用一个缺失的字段,$atan 返回 null。如果参数解析为 NaN,则 $tan 返回 NaN

示例
结果
{ $atan: NaN }
NaN
{ $atan: null }
null

三角学集合包含一个文档,该文档存储了直角三角形的三个边

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"side_a" : NumberDecimal("3"),
"side_b" : NumberDecimal("4"),
"hypotenuse" : NumberDecimal("5")
}

以下聚合操作使用$atan表达式计算与side_a相邻的角度,并使用$addFields管道阶段将其添加到输入文档中。

db.trigonometry.aggregate([
{
$addFields : {
"angle_a" : {
$radiansToDegrees : {
$atan : {
$divide : [ "$side_b", "$side_a" ]
}
}
}
}
}
])

$radiansToDegrees表达式将$atan返回的弧度值转换为等效的度数值。

该命令返回以下输出

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"side_a" : NumberDecimal("3"),
"side_b" : NumberDecimal("4"),
"hypotenuse" : NumberDecimal("5"),
"angle_a" : NumberDecimal("53.13010235415597870314438744090658")
}

由于side_bside_a存储为128位十进制数,因此$atan的输出是128位十进制数。

三角学集合包含一个文档,该文档存储了直角三角形的三个边

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"side_a" : NumberDecimal("3"),
"side_b" : NumberDecimal("4"),
"hypotenuse" : NumberDecimal("5")
}

以下聚合操作使用$atan表达式计算与side_a相邻的角度,并使用$addFields管道阶段将其添加到输入文档中。

db.trigonometry.aggregate([
{
$addFields : {
"angle_a" : {
$atan : {
$divide : [ "$side_b", "$side_a" ]
}
}
}
}
])

该命令返回以下输出

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"side_a" : NumberDecimal("3"),
"side_b" : NumberDecimal("4"),
"hypotenuse" : NumberDecimal("5"),
"angle_a" : NumberDecimal("0.9272952180016122324285124629224287")
}

由于side_bside_a存储为128位十进制数,因此$atan的输出是128位十进制数。

返回

$asinh