當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


CoffeeScript Math atan2()用法及代碼示例


描述

這個atan2()方法接受兩個數字並以弧度返回反正切值。此方法返回一個介於 -pi 和 pi 之間的數值,表示 (x, y) 點的角度 theta。

用法

下麵給出的是atan2()JavaScript 的方法。我們可以在 CoffeeScript 代碼中使用相同的方法。

Math.atan( x )

示例

下麵的例子演示了atan2()CoffeeScript 中的方法。將此代碼保存在具有名稱的文件中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

打開command prompt並編譯 .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);

現在,打開command prompt再次運行 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

相關用法


注:本文由純淨天空篩選整理自 CoffeeScript Math - atan2()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。