Coffeescript-math-atan2
提供:Dev Guides
CoffeeScript Math-atan2()
説明
- atan2()*メソッドは2つの数値を受け入れ、アークタンジェント値をラジアンで返します。 このメソッドは、-piとpiの間の数値を返し、(x、y)ポイントの角度シータを表します。
構文
以下に、JavaScriptの* atan2()*メソッドの構文を示します。 CoffeeScriptコードで同じメソッドを使用できます。
Math.atan( x )
例
次の例は、CoffeeScriptでの* atan2()メソッドの使用法を示しています。 このコードを *math_atan2.coffee という名前のファイルに保存します。
value = Math.atan2 90,15
console.log "The arc tangent value of 90,15 is : " + value
value = Math.atan2 15,90
console.log "The arc tangent value of 15,90 is : " + value
value = Math.atan2 0,-0
console.log "The arc tangent value of 0,-0 is : " + value
value = Math.atan2 +Infinity, -Infinity
console.log "The arc tangent value of +Infinity, -Infinity is : " + value
- コマンドプロンプト*を開き、以下に示すように.coffeeファイルをコンパイルします。
c:\> coffee -c math_atan2.coffee
コンパイル時に、次のJavaScriptが提供されます。
//Generated by CoffeeScript 1.10.0
(function() {
var value;
value = Math.atan(-1);
console.log("The arc tangent value of -1 is : " + value);
value = Math.atan(null);
console.log("The arc tangent value of null is : " + value);
value = Math.atan(20);
console.log("The arc tangent value of 20 is : " + value);
}).call(this);
次に、*コマンドプロンプト*を再度開き、以下に示すようにCoffeeScriptファイルを実行します。
c:\> coffee math_atan2.coffee
CoffeeScriptファイルを実行すると、次の出力が生成されます。
The arc tangent value of 90,15 is : 1.4056476493802699
The arc tangent value of 15,90 is : 0.16514867741462683
The arc tangent value of 0,-0 is : 3.141592653589793
The arc tangent value of +Infinity, -Infinity is : 2.356194490192345