CO 1301 Games Concepts Lecture 8 Basic Trigonometry
CO 1301: Games Concepts Lecture 8 Basic Trigonometry Dr Nick Mitchell (Room CM 226) email: npmitchell@uclan. ac. uk Hipparchos the “father” of trigonometry (image from Wikipedia) Material originally prepared by Gareth Bellaby
References â Rabin, Introduction to Game Development , Chapter 4. 1 â Van Verth & Bishop, Essential Mathematics for Games , Appendix A and Chapter 1 â Eric Lengyel, Mathematics for 3 D Game Programming & Computer Graphics â Frank Luna, Introduction to 3 D Game Programming with Direct 9. 0 c: A Shader Approach , Chapter 1
Lecture Structure â Introduction â Trigonometric functions: â sine, cosine, tangent â Circles â Useful trigonometric laws
Why study 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.
Mathematical Functions â A mathematical function defines a relationship between one variable and another. â A function takes an input (argument) and relates it to an output (value) according to some rule or formula. â For instance, the sine function maps an angle (as input) onto a number (as output). â The set of possible input values is the functions domain. â The set of possible output values is the functions range. â For any given input, there is exactly one output: â The 32 cannot be 9 today and 8 tomorrow! âMathematical Laws â I'll introduce some laws. I'm not going to prove or derive them. I will ask you to accept them as being true.
Greek letters â It is a convention to use Greek letters to represent angles and some other mathematical terms: α alpha β beta γ gamma θ theta λ lambda π pi Δ (capital) Delta
Trigonometry â Trigonometry arises out of an observation about right angled triangles. . . â Take a right angled triangle and consider one of its angles (but NOT the right angle itself). â We'll call this angle α. • The opposite side to α is y. • The shorter side adjacent to o (next to) α is x. • The longest side of the triangle (the hypotenuse) is h. a
Trigonometry â There is a relationship between the angle and the lengths of the sides. This relationship is expressed through one of the trigonometric functions, e. g. sine (abbreviated to sin). sin(α) = o / h o a
Values of sine degrees sin (degrees) 0 0 180 0 15 0. 26 195 -0. 26 30 0. 5 210 -0. 5 45 0. 71 225 -0. 71 60 0. 87 240 -0. 87 75 0. 97 255 -0. 97 90 1 270 -1 105 0. 97 285 -0. 97 120 0. 87 300 -0. 87 135 0. 71 315 -0. 71 150 0. 5 330 -0. 5 165 0. 26 345 -0. 26
Trigonometry You need to be aware of three trigonometric functions: sine, cosine and tangent. Function Symbol Definition Name sin sin(α) = o / h cosine cos(α) = a / h tangent tan(α) = o / a = sin(α) / cos(α) o a
Radians â You will often come across angles measured in radians (rad), instead of degrees (deg). . . â A radian is the angle formed by measuring one radius length along the circumference of a circle. â There are 2 p radians in a complete circle ( = 360°) = rad * 180° / p â rad = deg * p / 180° â deg
Trigonometry
Trigonometric 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 2 p or less than -2 p. 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.
Sine Wave and Cosine Wave Image taken from Wikipedia
Tangent Wave Image taken from Wikipedia
C++ â C++ has functions for sine, cosine and tangent within its libraries. â Use the maths or complex libraries: â The standard C++ functions use radians, not degrees. #include <cmath> using namespace std; float rad; float result; result = sin(rad); result = cos(rad); result = tan(rad);
PI â Written using the Greek letter p. â Otherwise use the English transliteration "Pi". â p is a mathematical constant. â 3. 14159 (approximately). â 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.
Circles âThe constant p is derived from circles so useful to look at these. âCircles are 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).
Circles âA tangent is a line drawn perpendicular to (at right angles to) the end point of a radius. âYou may know these from drawing splines (curves) in 3 ds Max. âYou'll see them when you generate splines in graphics and AI. âA chord is line connecting two points on a circle.
Circles âA segment is that part of a circle made by chord, i. e. a line connecting two points on a circle. âA sector is part of a circle in which the two edges are radii. sector
Circle â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.
Points 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.
Identities
Trigonometric Relationships âThis relationship is for right-angled triangles only: Where
Trigonometric Relationships âThese relationships are for right-angled triangles only:
Properties of triangles âThis property holds for all triangles and not just rightangled ones. âThe angles in a triangle can be related to the sides of a triangle.
Properties of triangles âThese hold for all triangles
Inverses â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 âIf x = sin(y) then y = arcsin(x) âThe inverse trigonometric functions are all prefixed with the term "arc": arcsine, arccosine and arctangent. âIn C++: asin() acos() atan()
Inverses â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(75 o) and sin(105 o) are both 0. 97. âTherefore an inverse trigonometric function typically has a restricted range so only one value can be generated.
Inverses Function Domain Range
- Slides: 30