The acos() function in p5.js is used to calculate the arc cosine value. The domain of this function is -1 to +1 and the range is 0 to 3.14.
Syntax:
acos(c)
Parameters: This function accepts single parameter c which stores the value in between -1 to 1.
Below programs illustrate the acos() function in p5.js:
Example 1: This example uses acos() function to calculate arc cosine value.
function setup() {
createCanvas(380, 80);
}
function draw() {
background(220);
let angle = PI;
let c = cos(angle);
let ac = acos(c);
textSize(16);
fill(color( 'red' ));
text( "Value of acos is : " + ac, 50, 30);
}
|
Output:
Example 2: This example uses acos() function to calculate arc cosine value.
function setup() {
createCanvas(380, 80);
}
function draw() {
background(220);
let c = 0.5;
let ac = acos(c);
textSize(16);
fill(color( 'red' ));
text( "Value of acos is : " + ac, 50, 30);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/acos
Last Updated :
23 Aug, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...