Docs 菜单
Docs 主页
/
MongoDB Manual
/ / /

$atan(聚合)

在此页面上

  • 行为
  • 例子
$atan

返回某个值的反正切值。

$atan 通过以下语法实现:

{ $atan: <expression> }

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

$atan 以弧度为单位返回值。使用 $radiansToDegrees 操作符,将输出值从弧度转换为度数。

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

有关表达式的更多信息,请参阅表达式

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

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

trigonometry 集合包含一个文档,该文档存储直角三角形的三条边:

{
"_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位十进制数。

trigonometry 集合包含一个文档,该文档存储直角三角形的三条边:

{
"_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

来年

$atan 2

在此页面上