Anda di halaman 1dari 5

Trig In Space:

A practical application of trigonometry




Trigonometry is not just used in a classroom. It can also be used in the
programming of games or iPhone apps. Trigonometry is required when working
with sprites (characters in games) and determining their rotation and distances.
This lesson will examine the use of trigonometry in programming a simple iPhone
app.

Warming Up

When programming, a programmer updates a sprites location by a certain speed
value. This value is actually a vector and has an X-Speed and a Y-Speed. When
moving around the sprite a programmer would like the sprite to rotate to face the
direction it is heading.












a) What trig function can we use to figure out the angle? What would the angle be
(in radians) if the Y-Speed is 5 and the X-Speed is 3?





b) Write a general formula that you would use in programming to figure out the
angle.




c) Now when programming the sprite, the rotation property is required to be in
degree mode, can you convert the answer from a to degrees? What is the formula
used to convert to degrees?


EXTENSION
If the coordinate system worked in the following way:


How would you convert from our traditional
angles, which go counter clockwise, to this
system? What would you have to do to the
angle that we are using?











d) It is also useful to know the actual speed of the ship (not just its two components,
but also the resultant vector). How can we calculate the value of the speed of the
ship given the X-Speed and the Y-Speed?















Take Off

It is no fun if our spaceship does not have an enemy to be wary of.
Let us add in a cannon that will follow our spaceship, we will need more
trigonometry for this piece.














a) Calculate the angle of rotation (in radians) if the coordinates of the ship are
(10,20) and the coordinates of the cannon are (3,5)





b) Convert that value to degrees so we can use it to set the rotation of the cannon.




c) When the ship comes in to contact with the cannon, it will bounce off in the
opposite direction at the same angle it was travelling towards the cannon. How can
we calculate the X-Speed and Y-Speed if the speed it ricochets off at is a constant
200?










Time for Orbit

Now we will add in an orbiting defense satellite that will act as a shield for the
cannon. The satellite rotates around the cannon at a fixed radius to form a circle.

















a) What is this familiar to? How can we calculate the X and Y coordinates of the
asteroid if we know the angle the arm makes and the radius R?







b) What is the angle made by an arc of length 170 units, if the satellite is orbiting 30
units away from the cannon?














c) If we described the rotation of the satellite in terms of its y coordinate as a
function of time we could see that it makes a sinusoidal graph. Given the following
table of values find the equation of the graph and sketch the graph.


Satellite Height
(y value)
Time (seconds)
0 0
10 0.5
25 1
35 1.5
25 2
10 2.5
0 3
-10 3.5
-25 4
-35 4.5
-25 5
-10 5.5
0 6




Lesson inspired by http://www.raywenderlich.com/35866/trigonometry-for-game-programming-part-1.

Anda mungkin juga menyukai