HTML and CSS Reference
In-Depth Information
Actually, you might get something like 0.4999 … something, which is not an error in your program but the
way binary computers sometimes end up representing floating-point numbers. It's close enough, though,
that you can consider it 0.5.
Now, it's fine for an abstract triangle like that to say that the angle is 30 degrees, and the measurements of
the sides are 1 and 2, but let's move it into the real world, or at least the world of the canvas coordinate
system. Remember that in the canvas element, positive vertical measurements go down, and positive
angle measurements go clockwise. So, in this case, the opposite side and the angle are both negative, as
you can see in Figure 3-9.
Figure 3-9. The same triangle in the canvas coordinate space
The ratio becomes -1/2, and we are talking about the sine of -30. We say that the sine of -30 degrees is -
0.5. Go ahead and change the JavaScript console.log statement to verify that:
console.log(Math.sin(-30 * Math.PI / 180));
That wasn't too painful, was it? Let's take a look at another trigonometry function: cosine.
Cosine
You can access cosine in JavaScript with Math.cos(angle) . Cosine is defined as the ratio of the adjacent
leg of an angle to the hypotenuse. Figure 3-10 shows that relationship.
 
Search WWH ::




Custom Search