p5.js | atan() Function

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.



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() { 
    // Create Canvas of size 270*80 
    createCanvas(550, 130); 
function draw() { 
    // Set the background color 
    // Initialize the parameter with some values
    let a = 0; 
    let b = 88; 
        let c = -1;
        let d = -0.5;
        let e = 5;
    // Call to atan() function 
    let v = atan(a);
        let w = atan(b);
        let x = atan(c);
        let y = atan(d);
        let z = atan(e);
    // Set the size of text 
    // Set the text color 
    // Getting arc tangent value 
    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);     



Reference: https://p5js.org/reference/#/p5/atan


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.