Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Fabric.js cos() Method

  • Last Updated : 04 Mar, 2021

The cos() method is used to return the cosine of a specified angle expressed in radians or degrees which is in range [-inf, +inf]. The returned value is in range [-1, +1].

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

cos(angle)

Parameters: This method accepts a parameter as mentioned above and described below:

  • angle: This parameter holds the specified angle in radians or degrees.

Return Value: This method returns the value in the range of -1 to +1.



Example 1:

Javascript




<!DOCTYPE html>
<html>
 
<head>
    <!-- Adding the FabricJS library -->
    <script src=
    </script>
</head>
 
<body>
    <script type="text/javascript">
 
        // Calling cos() function over
        // specified angles of 0 and 5
        console.log(fabric.util.cos(0));
        console.log(fabric.util.cos(5));
    </script>
</body>
 
</html>

Output:

1
0.28366218546322625

Example 2:

Javascript




<!DOCTYPE html>
<html>
 
<head>
    <!-- Adding the FabricJS library -->
    <script src=
    </script>
</head>
 
<body>
    <script type="text/javascript">
 
        // Specifying some angles
        var a = -1;
        var b = 0.6;
 
        // Calling cos() function over
        // above specified angles
        console.log(fabric.util.cos(a));
        console.log(fabric.util.cos(b));
    </script>
</body>
 
</html>

Output:

0.5403023058681398
0.8253356149096783



My Personal Notes arrow_drop_up
Recommended Articles
Page :