The atan() function in p5.js is used to calculate the inverse of tan() or arc tangent of a value ranging in between -Infinity to Infinity (exclusive) and gives result in the range of -π/2 to π/2.
Syntax:
atan(P)
Parameters: This function accepts a parameter “P” which is a value ranging from -1 to 1 and whose arc tangent is calculated.
Return Value: It returns the arc tangent of a value and its range is in between -π/2 to π/2.
Below program illustrates the atan() function in p5.js:
Example: This example uses atan() function to get arc tangent of a value.
function setup() {
createCanvas(550, 130);
}
function draw() {
background(220);
let a = 0;
let b = 88;
let c = -1;
let d = -0.5;
let e = 5;
let v = atan(a);
let w = atan(b);
let x = atan(c);
let y = atan(d);
let z = atan(e);
textSize(16);
fill(color( 'red' ));
text( "Arc tangent value of 0 is : " + v, 50, 30);
text( "Arc tangent value of 88 is : " + w, 50, 50);
text( "Arc tangent value of -1 is : " + x, 50, 70);
text( "Arc tangent value of -0.5 is : " + y, 50, 90);
text( "Arc tangent value of 5 is : " + z, 50, 110);
}
|
Output:

Reference: https://p5js.org/reference/#/p5/atan
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
23 Aug, 2023
Like Article
Save Article