定義
$sinラジアンで測定された値のサインを返します。
$sinの構文は次のとおりです。{ $sin: <expression> } $sintakes any valid expression that resolves to a number. If the expression returns a value in degrees, use the$degreesToRadiansoperator to convert the result to radians.$sinデフォルトでは、 は値をdoubleとして返します。$sin128<expression>は、 が128 ビットの 10 進数値に解決される限り、 ビットの 10 進数として値を返すこともできます。式の詳細については、「式 」を参照してください。
動作
null、NaN 、+/- Infinity
If the argument resolves to a value of null or refers to a field that is missing, $sin returns null. If the argument resolves to NaN, $sin returns NaN. If the argument resolves to negative or positive infinity, $sin throws an error.
例 | 結果 | |||
|---|---|---|---|---|
|
| |||
|
| |||
or
| 次の形式の出力のようなエラーメッセージをスローします。 |
例
trigonometryコレクションには、便宜的と 1 つの角度を直角三角形に保存するドキュメントが含まれています。
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "angle_a" : Decimal128("53.13010235415597870314438744090659"), "hypotenuse" : Decimal128("5") }
The following aggregation operation uses the $sin 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 : [ { $sin : {$degreesToRadians : "$angle_a"} }, "$hypotenuse" ] } } } ])
$degreesToRadians式は、 angle_aの度の値をラジアン単位の同等の値に変換します。
このコマンドは、次の出力を返します。
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "angle_a" : Decimal128("53.13010235415597870314438744090659"), "side_b" : Decimal128("4.000000000000000000000000000000000"), "hypotenuse" : Decimal128("5"), }
angle_aと はhypotenuse 128ビットの 10 進数として保存されているため、$sin の出力は128 ビットの 10 進数になります。
trigonometryコレクションには、便宜的と 1 つの角度を直角三角形に保存するドキュメントが含まれています。
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "angle_a" : Decimal128("0.9272952180016122324285124629224288"), "hypotenuse" : Decimal128("5") }
The following aggregation operation uses the $sin 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 : [ { $sin : "$angle_a" }, "$hypotenuse" ] } } } ])
このコマンドは、次の出力を返します。
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "angle_a" : Decimal128("0.9272952180016122324285124629224288"), "side_b" : Decimal128("4.000000000000000000000000000000000"), "hypotenuse" : Decimal128("5"), }
Since angle_a and hypotenuse are stored as 128-bit decimals, the output of $sin is a 128-bit decimal.