$tan (aggregation)
$tan
Returns the tangent of a value that is measured in radians.
$tan
の構文は次のとおりです。{ $tan: <expression> } $tan
takes any valid 式 that resolves to a number. If the expression returns a value in degrees, use the$degreesToRadians
operator to convert the result to radians.デフォルトでは、
$tan
は値をdouble
として返します。$tan
は、<expression>
が128ビットの 10 進数値に解決される限り、 128ビットの 10 進数として値を返すこともできます。
式の詳細については、「式演算子」を参照してください。
動作
null
、NaN
、+/- Infinity
If the argument resolves to a value of null
or refers to a field
that is missing, $tan
returns null
. If the
argument resolves to NaN
, $tan
returns NaN
.
If the argument resolves to negative or positive infinity,
$tan
throws an error.
例 | 結果 | |||
---|---|---|---|---|
|
| |||
|
| |||
or
| 次の形式の出力のようなエラーメッセージをスローします。
|
例
The trigonometry
collection contains a document that
stores one side and one angle in a right-angle triangle:
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "angle_a" : NumberDecimal("53.13010235415597870314438744090659"), "side_a" : NumberDecimal("3") }
The following aggregation operation uses the
$tan
expression to calculate the side opposite
to angle_a
and add it to the input document using the
$addFields
pipeline stage.
db.trigonometry.aggregate([ { $addFields : { "side_b" : { $multiply : [ { $tan : {$degreesToRadians : "$angle_a"} }, "$side_a" ] } } } ])
The $degreesToRadians
expression converts the
degree value of angle_a
to the equivalent value in radians.
このコマンドは、次の出力を返します。
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "angle_a" : NumberDecimal("53.13010235415597870314438744090659"), "side_a" : NumberDecimal("3") "side_b" : NumberDecimal(4.000000000000000000000000000000000") }
angle_a
とside_a
は128ビットの 10 進数 として保存されているため、 $tan
の出力は128ビットの 10 進数になります。
The trigonometry
collection contains a document that
stores the hypotenuse and one angle in a right-angle triangle:
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "angle_a" : NumberDecimal("0.9272952180016122324285124629224288"), "side_a" : NumberDecimal("3") }
The following aggregation operation uses the
$tan
expression to calculate the side adjacent
to angle_a
and add it to the input document using the
$addFields
pipeline stage.
db.trigonometry.aggregate([ { $addFields : { "side_b" : { $multiply : [ { $tan : "$angle_a" }, "$side_a" ] } } } ])
このコマンドは、次の出力を返します。
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "angle_a" : NumberDecimal("0.9272952180016122324285124629224288"), "side_a" : NumberDecimal("3") "side_b" : NumberDecimal("3.999999999999999999999999999999999") }
angle_a
とside_a
は128ビットの 10 進数 として保存されているため、 $tan
の出力は128ビットの 10 進数になります。