Some Maths David Meredith Aalborg University.

Slides:



Advertisements
Similar presentations
Transformations We want to be able to make changes to the image larger/smaller rotate move This can be efficiently achieved through mathematical operations.
Advertisements

CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
Angles and Their Measure Section 3.1. Objectives Convert between degrees, minutes, and seconds (DMS) and decimal forms for angles. Find the arc length.
Chapter 6: Trigonometry 6.3: Angles and Radian Measure
Radians and Degrees Trigonometry MATH 103 S. Rook.
I can use both Radians and Degrees to Measure Angles.
6.3 Angles & Radian Measure
Warm - up.
13.2 General Angles and Radian Measure. History Lesson of the Day Hippocrates of Chois ( BC) and Erathosthenes of Cyrene ( BC) began using.
Chapter 4 Trigonometric Functions
Angles and Polar Coordinates. Angles Angles are a way to describe the difference in slope of two intersecting lines Vertex Angle.
Radian Measure. Many things can be measured using different units.
Trigonometry Day 1 ( Covers Topics in 4.1) 5 Notecards
Trigonometry The science of studying angle measure.
Continuous Random Variables Continuous Random Variables Chapter 6.
4.1 Day 1 Angles & Radian Measure Objectives –Recognize & use the vocabulary of angles –Use degree measure –Use radian measure –Convert between degrees.
RADIANS Radians, like degrees, are a way of measuring angles.
Section 7-1 Measurement of Angles. Trigonometry The word trigonometry comes two Greek words, trigon and metron, meaning “triangle measurement.”
C2:Radian Measure Learning Objective: to understand that angles can be measured in radians.
RADIAN THE UNIT CIRCLE. REMEMBER Find the circumference of a circle that has a radius of 1. C = 2πr C = 2π(1) C = 2π.
11: :00 Circles and Pi 1 What is a circle? Help pupils articulate it:  Draw what they describe  Encourage pupils to improve description if stuck,
7.1 Measurement of Angles -If you leave this class with anything this year, it will be a better understanding of sine/cosine/tangent and angle measurments.
Holt McDougal Algebra Angles of Rotation Warm Up Find the measure of the supplement for each given angle. Think back to Geometry… °2. 120°
MATH 1330 Section 4.2 Radians, Arc Length, and Area of a Sector.
WARM UP 1. Sketch the graph of y = tan θ 2. What transformation of function f is represented by g(x) = 3 f(x)? 3. Write the general equation of a quadratic.
13-3 The Unit Circle Warm Up Lesson Presentation Lesson Quiz
Calculus, Section 1.4.
5.1 The Unit Circle.
David Meredith Aalborg University
Warm Up Find the measure of the supplement for each given angle.
Welcome to Trigonometry!!
Copyright © 2014 Pearson Education, Inc.
Chapter 10 - Rotational Kinematics
Arcs, Sectors & Segments
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
The Trigonometric Functions
Notes 6-1: Radian Measure
Circular Motion.
Do Now Find the value of each expression. Sin 60 ° Cos 30 ° Tan 270 °
Angles and Their Measurements
What is a Radian? Before we begin our investigation of a radian let us first establish a definition of an angle and review some important concepts from.
Terms to know going forward
COORDINATE PLANE The plane containing the "x" axis and "y" axis.
CIE Centre A-level Pure Maths
7.1 Radian and Degree measure
MATH 1330 Section 4.2.
Objectives Convert angle measures between degrees and radians.
Fitting Curve Models to Edges
Intro to Trigonometry For the Greeks, trigonometry dealt with the side and angle measures of triangles, practical math for building stuff and locating.
Chapter 8: The Unit Circle and the Functions of Trigonometry
5.1 The Unit Circle.
Trigonometry Extended: The Circular Functions
CO1301: Games Concepts Lecture 13 Basic Trigonometry
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
Rotation On Cartesian grid.
Precalculus Essentials
11.1 Vocabulary Circumference PI () Arc Length Radian.
13.2A General Angles Alg. II.
How do we convert angle measures between degrees and radians?
Warm Up a)Find the measure of the reference angle for each given angle. b) Find a pair of positive and negative coterminal angles for each given value.
Chapter 8: The Unit Circle and the Functions of Trigonometry
Measuring Angles in Radians
Transformations for GCSE Maths
Section 3.1 Radians and Angles in Standard Position
MATH 1330 Section 4.2.
Definition y Radian: The length of the arc above the angle divided by the radius of the circle. x in radians ,
13-3 – Radian Measures.
Trig Graphs and reciprocal trig functions
11.1 Vocabulary Circumference PI () Arc Length Radian.
Presentation transcript:

Some Maths David Meredith Aalborg University

Source This lecture is based on Chapter 13 of Shiffman, D. (2008). Learning Processing. Morgan Kaufmann. ISBN:

Maths and programming BAD NEWS: – You can’t build interesting image and sound systems without using some maths – You’ll need to be able to think logically in order to implement your creative ideas GOOD NEWS: – You don’t have to know a lot of maths in order to be able to build interesting image and sound systems – The maths you need to know isn’t that hard – Your ability to think logically will improve quickly with practice!

We’ve already used some maths Making a ball move and bounce off the side of the display area Checking if two circles intersect

Overview We’re going to cover the following – Modulus – Random numbers – Probability – Perlin noise – Angles – Trigonometry – Oscillation – Recursion – Two-dimensional arrays

Modulus This is just clock arithmetic If y = x mod n then y is the number you land on if you count x steps clockwise around a circle with n numbers on it, starting at 0 x mod n is the remainder after you divide x by n E.g. 10 mod 7 = 3 (12 - 6) mod 5 = 1 Also works when x and n are floats: 6.4 mod 2.5 = 1.4 In Processing, use % to do the mod operation 10 % 7 = 3 (12 - 6) % 5 = % 2.5 = 1.4

Modulus example

Random numbers The random(x) and random(x,y) functions return a pseudo-random number For example, random(10) returns a pseudo-random number between 0 (inclusive) and 10 (exclusive) The random() function generates a random number over the desired range according to a uniform distribution – i.e., (int)random(10) generates 0, 10% of the time 1, 10% of the time 2, 10% of the time …

Distribution of random numbers

Probability review To calculate the probability of an outcome having a desired property, you need to know – the total number of possible outcomes, N – the number of these possible outcomes that have the desired property, x Probability is then x/N For example, to calculate the probability of the number on a die being less than 3 – total number of possible outcomes is 6 (1,2,3,…6) – number of outcomes with desired property is 2 (1,2) – So probability is 2/6 = 1/3

Compound probability Probability of two sixes in a row is equal to the probability of getting a six the first time multiplied by the probability of getting a six the second time 1/6 * 1/6 = 1/36 All possible outcomes are – (1,1), (1,2), (1,3),…(2,1),(2,2),(2,3)…(6,4),(6,5),(6,6) – Therefore 36 possible outcomes Only one of these 36 outcomes is 2 sixes in a row Therefore probability of getting two sixes in a row is 1/36 What’s the probability of drawing 3 aces in a row from a pack of cards?

Drawing three aces in a row Probability of drawing 3 aces in a row is equal to – probability of drawing first ace (4/52) multiplied by – probability of drawing second ace (3/51) multiplied by – probability of drawing third ace (2/50) Therefore – 4/52 * 3/51 * 2/50 = = 18/100000

Controlling event probabilities Generate a random number between 0 and 1 Partition the range into sizes that correspond to the desired probabilities of the different events – e.g., for a probability of for a probability of for a probability of 0.3

Perlin noise We can get a “life-like” or “natural” effect by introducing noise into values – e.g., by adjusting mathematically computed values by small random amounts To make an effect life-like, we don’t want too much randomness Ken Perlin devised a function that generates noise that seems “natural” or “organic” The random number generated by Perlin noise is constrained to being not too far away from the preceding value This gives an “organic”, “natural” smooth, but unpredictable curve, in contrast to truly random noise, which is much more erratic

noise() The Processing noise() function generates Perlin noise It takes 1, 2 or 3 arguments, depending on the dimensionality of the noise to be generated – In 3 dimensions, the function generates a random 3d point In 1d, the argument can be thought of as being “time” – The argument would be the value of the x axis in the graph above, and the value returned would be the y value Typically, we start with a time value of 0 and then increment this value by a certain amount to generate the next noise value – The more we increment the time value on each step, the less smooth the curve looks

Using the noise() function

Pulsating blob

Angles We need to understand angles in order to rotate things and draw things with circular symmetry You are probably used to measuring angles in degrees – 90 degrees is a quarter turn, – 180 degrees is a half turn – 270 degrees is a ¾ turn – 360 degrees is a full turn Usually measure angles anti-clockwise from the positive x- axis

Radians In maths and Processing, we measure angles in radians 1 radian is the angle for which the length of the circular arc is the same as the radius Remember that the circumference of a circle of radius r is 2πr – Since 1 radian corresponds to travelling r along the circumference and a full trip round a circle is 2πr long, there are 2π radians in a full turn 2π radians = 360 degrees π radians = 180 degrees π/2 radians = 90 degrees 3π/2 radians = 270 degrees ? = 45 degrees In general, Radians = 2π * (degrees/360) In Processing, π is given by PI, so 2π would be “2 * PI” In Processing, we can use the radians function to convert degrees to radians: float angle = radians(60); //Returns the radian equivalent of 60 degrees

Trigonometry

Converting from polar to Cartesian co-ordinates Processing uses Cartesian co-ordinates, so if you construct something with circular symmetry, you have to convert from polar to Cartesian co-ordinates

Polar to Cartesian (x,y) co-ordinates

Spiral

Oscillation Graph shows sin(x) for various values of x Physical objects oscillating due to gravity often move according to this curve – This is called simple harmonic motion – e.g., a pendulum

Pendulum

Fractals and recursion Term, fractal, coined by Benoit Mandelbrot in 1975 to mean a form that looks the same at all scales (i.e., regardless of whether zoomed in or zoomed out) Many natural forms resemble fractals – e.g., snow-flakes, mountains, coastlines Can create fractals by using recursive functions

Recursion A recursive function is one that calls itself Every recursive function must have an exit condition such that when this is true, the function does not call itself

Don’t try drawing this with a for loop!

Two-dimensional arrays We’ve already met 1-dimensional arrays A two-dimensional array is just an array in which each box holds a 1-dimensional array We iterate through a 1-dimensional array with a for loop We iterate through a 2-dimensional array with a for-loop, nested inside another for-loop

Two-dimensional arrays