Trigonometry is an important part of the math curriculum in academics. It involves the study of triangles, properties of angles, relationships in triangle, evaluating measurements of height, distance, and angles. The applications of this topic are not just confined to exams or test series but also in our day to day life and other important career prospects.
It is used extensively in surveying, statistics, navigation, engineering, astronomy, and other fields. Critical thinking is required to have a good grip over every corner of this topic. Students must be well versed in the fundamentals. But the sad reality is, most of the students hate dealing with trigonometry.
Sporadic pattern of solutions is one of the main reasons behind it. Early adaptation to the topic with good practice is the only solution to the issue. This post has been developed keeping in mind the little learners who struggle in this topic. One thing that always works out well when dealing with issues in math i.
There are numerous ways of turning maths into a fun learning subject. One such is to present it to the kids in a form that they like the most. Yes, you guessed it right! May it be indoor, outdoor, board, or mobile games. Kids learn while playing. Open a Terminal window to the directory where you downloaded Cocos2D and enter the following command:. Name the project TrigBlaster and set the device family to iPhone. Build and run the template as-is.
If all works OK, you should see the following:. Luckily, enabling ARC is really easy. Expand the drop-down and select only the last four files main. Note: When you convert a project to ARC or make other large changes, Xcode will prompt you to enable snapshots for the current project.
A snapshot saves the state of the entire project as if you copied and pasted the project into another directory. You can learn more about snapshots over here. For the purposes of this tutorial, select disable. Next download the resources for this tutorial. This file contains the images for the sprites and the sound effects. Unzip it and drag the Images and Sounds folders into Xcode to add them to the project.
Because this is a simple game, you will be doing all your work inside a single class: the HelloWorldLayer. There is also a bunch of code in the. Replace HelloWorldLayer. The scene method is unchanged from the template, but init now calls [super initWithColor] to set a purple background color on the layer.
You will need some instance variables for this, so modify the implementation line in HelloWorldLayer. This is all pretty basic if you have worked with Cocos2D before. The player sprite is positioned in the bottom-right corner of the screen. Unfortunately, the iOS Simulator cannot simulate the accelerometers. That means that from now on, you will need to run the app on your device to test it.
Note: If you are unsure how to put the app on your device, check out this extensive tutorial that explains how to obtain and install the certificates and provisioning profiles that allow Xcode to run apps on your device. To prevent that from happening, go into the Target Settings screen and in the Summary tab under Supported Interface Orientations , de-select all options except for Landscape Right.
Using the accelerometers from code is pretty straightforward. You first ask Cocos2D to activate the accelerometers. Once enabled, it sends you periodic updates with the values of the three accelerometers that are built into the iPhone. You then use these values to change the speed of the spaceship.
First, add new instance variables to keep track of the accelerometer values. A good place to activate the accelerometers is inside init. Add the following line to it:.
Note: An accelerometer records how much gravity currently pulls on it. Because the user is holding the iPhone in her hands, and hands are never completely steady, there are a lot of tiny fluctuations in this gravity value.
We are not so much interested in these unsteady motions as in the larger changes in orientation that the user makes to the device. By applying this simple low-pass filter , you retain this orientation information but filter out the less important fluctuations. You need some more instance variables to pull this off.
This defines two constants, the maximum acceleration points per second squared and the maximum speed points per second. This is a basic technique for controlling a sprite using the accelerometers.
When the device is tilted to the left, you give the player maximum acceleration to the left. Conversely, when the device is tilted to the right, you give the player maximum acceleration to the right. Likewise for the up and down directions.
Remember that this game is in landscape, so the Y-accelerometer runs from left to right in this orientation, and the X-accelerometer from top to bottom. Without this, the spaceship would move about sixty times faster than it should! You could write this using an if statement instead:. However, I like the succinctness of the one-line version.
That should do it. Build and run the game. You can now control the spaceship by tilting the device. If you skipped ahead to this section, here is the starter project at this point. In this tutorial, you will not be using these functions — instead you will be going low level and issuing the raw trigonometry calls yourself, for the learning experience.
In an actual game, you might want to use the wrapper methods however. It would be cool — and much less confusing to the player!
To rotate the spaceship, you need to know the angle to rotate it. So basically, you know 2 sides of a right triangle, so you are in the Know 2 Sides, Need Angle case mentioned in the beginning of this tutorial.
That means you need to use one of the inverse functions: arcsin, arccos or arctan. You know the opposite and adjacent sides, so you want to use the arctan function to find the angle to rotate the ship. Remember, that looks like the following:. The Objective-C math library comes with the atan function that computes the arc tangent, but it has one big issue: what if the x-speed is 0?
In that case, the adjacent is 0 and dividing by 0 is mathematically undefined. Your app might crash or just behave weirdly when that happens. In other words, we finally get to see some action! The red object, Base, is somewhat centered. It creates objects, Bullets. Look at the code, to see how it works. Next, we will make it a little more dynamic. We will also clean it up a little, because you'll notice that things aren't centered, and the bullet ends up being slightly off where you want it to go.
This time, the Bullet has an alterable value, 'vel' velocity that it will travel. We can change this, because it is a variable. We are not longer limited to 10! If you hold down the left mouse button, all the existing bullets will slow down. We could have them initialize at this speed from a global value that they all look at upon creation, but let's keep it simple. Holding down the right button will add to the rotation, so they will curve. Let's go over what we can do with trigonometry so far: We can determine an angle given an x and y difference.
We can determine x and y movement when given an angle and speed. Let's look at that second one. So far we've used angle A for the angle, but what if we used an unrelated angle? An angle that always increases. We can create a satellite, an object that circles around another.
Let's take a look at how that turns out, below. Comments explain what's going on. The next frame will be slight changes to this example. Let's step back a bit, and look at Sin x.
You don't need to understand the unit circle quite yet, unless you want very specific waves. For now, you can understand the following Just know how a sine wave reacts:. This will repeat even after you go above Cosine - Unit Circle Match the angle in degrees on the unit circle with the cosine value. Radians - Unit Circle Given the radians find the angle in degrees. Unit Circle - Radian Measure Determine the location on the unit circle of the given radian measure. Sine and Cosine Evaluate sine and cosine of angles in degrees.
Trigonometric Identities Match the following Trig Identities. Trigonometric Formulas Pythagorean and Reciprocal Identities.
0コメント