<< Chapter < Page Chapter >> Page >

Plotting all of these point is going to require a lot of effort. Before you do that, let's think about it.

Two full cycles

You should have been able to discern by now that your plots for the sine and cosine graphs each contain two full cycles. An important thing aboutperiodic functions is that once you know the shape of the curve for any one cycle, you know the shape of the curve for every cycle from minus infinity to infinity. Theshape of every cycle is exactly the same as the shape of every other cycle.

Saving patience and effort

If you are running out of patience, you might consider updating your plots for only one cycle.

You should be able to discern that your curves no longer have a saw tooth shape. Each time we have run the script, we have sampledthe amplitude values of each curve at twice as many points as before. Therefore, the curves should be taking on a smoother rounded shape that is betterrepresentation of the actual shape of the curves.

Continue the process

You can continue this process of improving the curves for as long as you have the space and patience to do so. Just divide the value of the variable named angInc by a factor of two and rerun the script. That will produce twice as many data points that are only half as far apart on thehorizontal axis.

If you choose to do so, you can plot only the new points in one-half of a cycle to get an idea of the shape. By now you should have discerned that each half of a cycle has the same shape, only onehalf is above the horizontal axis and the other half is a mirror image below the axis.

Plot of cosine and sine curves

Figure 14 shows a cosine curve plotted above a sine curve very similar to the curves that you have plotted on your graph paper.

Figure 14 - Plot of cosine and sine curves.

missing image

Grid lines

The image in Figure 14 contains 7 vertical grid lines. The vertical grid line in the center represents an angle of zero degrees. The space between each gridline on either side of the center represents an angle of 90 degrees or PI/2 radians.

There are two horizontal grid lines. One is one-fourth of the way down from the top. The other is one-fourth of the way up from the bottom.

The curves

A cosine curve is plotted with vertical values relative to the top grid line. It extends from -360 degrees on the left to +360 degrees on the right.

A sine curve is plotted with vertical values relative to the bottom grid line. It also extends from -360 degrees on the left to +360 degrees on theright.

Return values for the Math.asin, Math.acos, and Math.atan methods

I told you earlier that the Math.asin method returns a value between -PI/2 and PI/2. However, I didn't tell you that the Math.acos method returns a value between 0 and PI, or that the Math.atan method returns a value between -PI/2 and PI/2. You now have enough informationto understand why this is true.

Smooth curves

If you examine the two curves in Figure 14 and the data in Figure 13 , you can surmise that the sine and cosine functions are smooth curves whose values range between-1 and +1 inclusive. For every possible value between -1 and +1, there is an angle in the range -PI/2 and PI/2 whose sine value matches that value. There isalso an angle in the range 0 and PI whose cosine value matches that value.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Game 2302 - mathematical applications for game development. OpenStax CNX. Jan 09, 2016 Download for free at https://legacy.cnx.org/content/col11450/1.33
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?

Ask