Welcome to Bucaro TecHelp!

Bucaro TecHelp
HTTPS Encryption not required because no account numbers or
personal information is ever requested or accepted by this site

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Java Script Math.cos Method

Cosine is a trigonometric function. Based on a right triangle. It's the ratio of the length of the adjacent side to the length of the hypotenuse.

cosine A = adjacent/hypotenuse

Identifying the sides of a right triangle

In identifying the sides of a right triangle, the side next to the angle for which we are using the trigonometric function is called the adjacent side. The side opposite that angle is called the opposite side.

If you know an angle and the length of the side adjacent to the angle, you can use the cosine of the angle to calculate the length of the hypotenuse.

length of hypotenuse = length of adjacent/cosine of angle

Example

angle = 35 degrees
opposite side = 8

Java Script Using Math.cos Method

<script type="text/javascript">

var angle = 35;
var adjacent = 8;

var hypotenuse = adjacent/Math.cos(35 * Math.PI/180);

alert(hypotenuse.toFixed(3));

</script>

The code shown above uses the Java Script Math.cos method. The Math.cos method requires the angle passed to it to be in radians. A radian is the angle of an arc created by wrapping the radius of a circle around its circumference. It sounds like a weard unit, by by coincidence there are 2 PI radians in a complete circle. This makes this much easier in fields like calculus. To convert degrees to radians, multiply by PI/180.

The code shown above also uses the Number objects .toFixed(n) method. This method converts a value to a number with n digits to the right of the decimal point.

More Java Script Code:
• The Navigator Object
• Java Script Math.tan Method
• Interactively Set Webpage Colors
• The Java Script window.open Method
• The for Loop
• Determine Absolute Value
• Window Object Properties and Methods
• Java Script Events
• Use moveBy Method to Move Window by a Specific Offset
• Search and Replace Strings

RSS Feed RSS Feed

Follow Stephen Bucaro Follow @Stephen Bucaro


Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2024 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268