### Present Remotely

Send the link below via email or IM

• Invited audience members will follow you as you navigate and present
• People invited to a presentation do not need a Prezi account
• This link expires 10 minutes after you close the presentation

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

# Trig In Computer Graphics

No description
by

## David Baird

on 3 March 2015

Report abuse

#### Transcript of Trig In Computer Graphics

How Does Trig Apply to Programming?
Trig is used in many different ways in computer programs.
Primarily to: create, move, and position objects around the plane.
Trig is used to create the objects it can manipulate later through simple shape building.
The program needs trig to build the shapes so that it can figure out the correct proportion for the size of them.
Cyclical Processes
Cyclical processes on computers are used to create swinging motion and circular motion on the screen using sinusoidal functions being entered into the program.
Sinusoidal functions are great at representing repeating motion.
On a standard sine wave one period is 2 pi radians in length or 360 degrees.
Measuring Position
Lets start off with the simplest example: triangles.
Traingles are everywhere in games.
Triangles are generally used to measure the distance between two objects on the screen.
Ex: Spaceship Game (shown below)
Lets say you want to find the distance between the two spaceships i.e. the hypotenuse.
You have the coordinates of these two ships on the grid and then can use those to find sides a and b of the triangle.
From there it is a simple Pythagorean equation.
In first person games they use this same idea to measure objective distances.
In a first person game you'll usually have an objective tracker that tells you how far away you are from the quest objective. To measure the distance they measure how far away it is in the x and y direction then use Pythagorean Theorem.
Collision Detection On Screen
Collision detection on screen uses trig as well with the use of circles.
When designing a video game like the spaceship game, without a physics engine the spaceships would just fly through each other.
Creating a collision system allow the ships to bounce off one another and their surroundings.
Cyclical Processes Example
Ex: A pendulum swing=one period or one 360 degree rotation around a circle.
The distance the pendulum moves during its period can be altered by changing the amplitude of the function, the speed at which the pendulum swings can be altered by changing the period of the function.
In a pendulum computer program the distance the pendulum takes to swing from one side to dead center is the amplitude.
The period of a pendulum is the time it takes to make one full back and forth swing.
The equation for this program: pendulum angle= range * sin(time*speed)
The speed value is not mph it's full swings per second.
A number less than 1 slows the pendulum down while a number higher than 1 speeds it up.
Trig In Computer Programming
Collisions Continued
Set up circles
Set up circles around each object you want to be able to collide with other objects.
Pythagorean Theorem is needed to find the radius of each circle.
The system then determines if the distance between the two objects is less than the radius of the two circles combined.
If the distance is less then its a hit.
While trig can be used to calculate far more complex shapes to determine collision areas, circles are generally close enough for the task at hand.
They are also much easier to calculate.
Collisions Continued
Set up the circles around each object you want to collide against one another.
All that is necessary to know is the radius and that can be found using the Pythagorean Theorem.
In the program a collision only happens when the distance between the two objects is less than or equal to the two radii added together.
Trig can be used to calculate more complex objects but circles work best because they are generally close enough and easier to calculate than a complex object.
Pendulum Wave Video
Works Cited
http://www.raywenderlich.com/35866/trigonometry-for-game-programming-part-1
http://galileospendulum.org/2011/05/24/physics-quanta-the-pendulums-swing/