Fabric.js cos() Method

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:
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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek 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!



