Title: CO1301 Games Concepts Week 18 Basic Trigonometry
1CO1301 - Games ConceptsWeek 18Basic
Trigonometry
2References
- Rabin, Introduction to Game Development, Chapter
4.1 - Van Verth Bishop, Essential Mathematics for
Games, Appendix A and Chapter 1. - Eric Lengyel, Mathematics for 3D Game Programming
Computer Graphics - Frank Luna, Introduction to 3D Game Programming
with Direct 9.0c A Shader Approach, Chapter.1.
3Lecture Structure
- Introduction
- Trigonometric functions sine, cosine, tangent
- Circles
- Useful trigonometric laws
4Why do Trigonometry?
- Why is trigonometry relevant to your course?
- Games involve lots of geometrical calculations
- Rotation of models.
- Line of sight calculations.
- Collision detection.
- Lighting.
- For example, the intensity of directed light
changes according to the angle at which it
strikes a surface. - You require a working knowledge of geometry.
5Introduction
- Mathematical Functions
- A mathematical function defines relationship
between one variable and another. A function
takes an input and calculates an output
according to some rule or operation. For
instance, sine function takes an angle as input
and calculates a number. - Mathematical Laws
- I'll introduce some laws. I'm not going to prove
or derive them. I'm going to ask you to accept as
being true.
6Greek letters
- It is a convention to use Greek letters to
represent angles and some other mathematical
terms.
7- Part 2 Trigonometric functions sine, cosine,
tangent
8Trigonometry
- Trigonometry arises out of an observation about
right angled triangles. - Take a right angled triangle and consider one of
its angles (not the right angle itself). We'll
call this angle a.
- The opposite side to the angle is y.
- The nearest side to the angle is x.
- The longest side of the triangle is h.
9Trigonometry
- There is a relationship between the angle and the
lengths of the sides. This relationship is
expressed through a trigonometric function, e.g.
sine (abbreviated to sin).
sin(a) y / h
10Values of sine
11Trigonometry
You need to be aware of three trigonometric
functions sine, cosine and tangent.
12Trigonometry
13Trigonometric Functions
- Sine, cosine and tangent are mathematical
functions. - There are other trigonometric functions, but they
are rarely used in computer programming. - Angles can be greater than 2p or less than -2p.
Simply continue the rotation around the circle. - You can draw a graph of the functions. The x-axis
is the angle and the y-axis is (for example)
sin(x). If you graph out the sine function then
you create a sine wave.
14Sine Wave and Cosine Wave
Image taken from Wikipedia
15Tangent Wave
Image taken from Wikipedia
16C
include "math.h" OR USE include
ltcomplexgt using namespace std
- C has functions for sine, cosine and tangent
wiithin its libraries. Use the maths or complex
libraries - The standard C functions use radians, not
degrees.
float rad float result result
sin(rad) result cos(rad) result tan(rad)
17Radians
- A degree is a fairly arbitrary measurement of
rotation. More common to use radians. - A complete revolution is equal to 2p radians.
- 2p radians is equal to 360 degrees.
18PI
- Written using the Greek letter p.
- Otherwise use the English transliteration "Pi".
- p is a mathematical constant.
- p is the ratio of the circumference of a circle
to its diameter. This value holds true for any
circle, no matter what its size. It is therefore
a constant. - 3.14159 (approximately).
19 20Circles
- The constant p is derived from circles so useful
to look at these. - A basic shape.
- Circumference is the length around the circle.
- Diameter is the width of a circle at its largest
extent, i.e. the diameter must go through the
centre of the circle. - Radius is a line from the centre of the circle to
the edge (in any direction).
21Circles
- Tangent is a line drawn perpendicular to the end
point of a radius. You'll know these from drawing
splines (curves) in 3ds Max. You'll see them
again when you generate splines in graphics and
AI. - Chord is line connecting two points on a circle.
22Circles
- Segment is that part of a circle made by chord,
i.e. a line connecting two points on a circle. - Sector is part of a circle in which the two edges
are radii.
23Circle
- Using Cartesian coordinates.
- Centre of the circle is at (a, b).
- The length of the radius is r.
- The length of the diameter is d.
24Points on a Circle
- Imagine a line from the centre of the circle to
(x,y) - a is the angle between this line and the x-axis.
25- Part 4 Useful trigonometric laws
26Identities
27Trigonometric Relationships
- This relationship is for right-angled triangles
only.
Where
28Trigonometric Relationships
- These relationships are for right-angled
triangles only.
29Properties of triangles
- This property holds for all triangles and not
just right-angled ones. - The angles in a triangle can be related to the
sides of a triangle.
30Properties of triangles
- These hold for all triangles
31Inverses
- Another bit of terminology and convention you
need to be familiar with. - An inverse function is a function which is in the
opposite direction. An inverse trigonometric
function reverses the original trigonometric
function, so that - x sin(y) y arcsin(x)
- The inverse trigonometric functions are all
prefixed with the term "arc" arcsine, arccosine
and arctangent. - In C asin() acos() atan()
32Inverses
- The notation sin-1, cos-1 and tan-1 is common.
- We know that trigonometric functions can produce
the same result with different input values, e.g.
sin(75o) and sin(105o) are both 0.97. - Therefore an inverse trigonometric function
typically has a restricted range so only one
value can be generated.
33Inverses
Function
Domain
Range