📜  p5.js | acos()函数

📅  最后修改于: 2022-05-13 01:56:48.351000             🧑  作者: Mango

p5.js | acos()函数

p5.js 中的acos()函数用于计算反余弦值。这个函数的域是-1到+1,范围是0到3.14。

句法:

acos(c)

参数:此函数接受单个参数c ,该参数将值存储在 -1 到 1 之间。

下面的程序说明了 p5.js 中的 acos()函数:

示例 1:本示例使用 acos()函数计算反余弦值。

function setup() {
  
    // Create Canvas of size 380*80
    createCanvas(380, 80);
}
  
function draw() {
      
    // Set the background color
    background(220);
      
    // Set the angle in radian
    let angle = PI;
      
    // Compute value of cos()
    let c = cos(angle);
  
    // Compute value of acos()
    // It returns the value of PI
    let ac = acos(c);
      
    // Set the font size
    textSize(16);
      
    // Set the font color
    fill(color('red'));
      
    // Display result
    text("Value of acos is : " + ac, 50, 30);
}

输出:

示例 2:本示例使用 acos()函数计算反余弦值。

function setup() {
  
    // Create Canvas of given size
createCanvas(380, 80);
}
  
function draw() {
      
    // Set the background color
    background(220);
      
    let c = 0.5;
      
    // Use acos() function to calculate
    // arc cosine value
    let ac = acos(c);
      
    // Set font size
    textSize(16);
      
    // Set font color
    fill(color('red'));
      
    // Display result
    text("Value of acos is : " + ac, 50, 30);
}

输出:

参考: https://p5js.org/reference/#/p5/acos