AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

$atan2(式演算子)

$atan2

y / xの逆タンジェント(アーク タンジェント)を返します。 yxはそれぞれ式に渡される最初と 2 番目の値です。

$atan2 の構文は次のとおりです。

{ $atan2: [ <expression 1>, <expression 2> ] }

$atan2 takes any valid expression that resolves to a number.

$atan2 returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees.

$atan2デフォルトでは、 は値をdouble として返します。$atan2 128<expression>は、 が128 ビットの 10 進数値に解決される限り、 ビットの 10 進数として値を返すこともできます。

式の詳細については、「式 」を参照してください。

$atan2に指定された引数のいずれかがnullの場合、式はnullを返します。 いずれかの引数がNaNの場合、式はNaNを返します。 1 つの引数がnullで、もう 1 つの引数がNaNの場合、式はnullを返します。

結果

{ $atan2: [ NaN, <value> ] }

NaN

{ $atan2: [ <value>, NaN ] }

NaN

{ $atan2: [ null, <value> ] }

null

{ $atan2: [ <value>, null ] }

null

{ $atan2: [ NaN, null ] }

null

{ $atan2: [ null, NaN ] }

null

trigonometryコレクションには、直角三角形の 3 つの面を保存するドキュメントが含まれています。

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

The following aggregation operation uses the $atan2 expression to calculate the angle adjacent to side_a and add it to the input document using the $addFields pipeline stage.

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

The $radiansToDegrees expression converts the radian value returned by $atan2 to the equivalent value in degrees.

このコマンドは、次の出力を返します。

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

side_bと はside_a 128ビットの 10 進数として保存されているため、$atan2 の出力は128 ビットの 10 進数になります。

trigonometryコレクションには、直角三角形の 3 つの面を保存するドキュメントが含まれています。

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

The following aggregation operation uses the $atan2 expression to calculate the angle adjacent to side_a and add it to the input document using the $addFields pipeline stage.

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

このコマンドは、次の出力を返します。

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

Since side_b and side_a are stored as 128-bit decimals, the output of $atan2 is a 128-bit decimal.

このページを評価

項目一覧