beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

55
Beginning Direct3D Game Programming: Mathematics 4 Calculus [email protected] Division of Digital Contents, DongSeo University. March 2016

Upload: jintaek-seo

Post on 13-Feb-2017

42 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Beginning Direct3D Game Programming:Mathematics 4

[email protected]

Division of Digital Contents, DongSeo University.March 2016

Page 2: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Singularity In mathematics,

a singularity is in general a point at which a given mathematical object is not defined, or a point of an exceptional set where it fails to be well-behaved in some particular way, such as differentiability.

For example, f(x) is singu-lar when x≡0.

2

Page 3: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

The function f(x) = |x| also has a singularity at x= 0, since it is not differentiable there.

3

Page 4: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

The graph defined by y2 = x also has a singularity at (0,0), this time because it has a "corner" (vertical tan-gent) at that point.

4

Page 5: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Differentiation

5

f(x)=x2

Page 6: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Differentiation The derivative of a function of a real variable measures

the sensitivity to change of a quantity (a function value or dependent variable) which is determined by another quantity (the independent variable).

Derivatives are a fundamental tool of calculus. For example, the derivative of the position of a moving

object with respect to time is the object's velocity: this measures how quickly the position of the object changes when time is advanced.

6

Page 7: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

The slope m of the secant line is the difference between the y values of these points divided by the difference between the x values, that is:

7

Page 8: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

8

Page 9: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

9

Page 10: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Practice Write a function that calculate the derivative of x2. For example, FPrime( float x ) returns a f'(x2). Print the tangent line at (3.0, f(3.0)).

10

Page 11: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Get the slope of (3,9) of y=x2

11

Page 12: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

12

Page 13: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

(dp is infinitely small, so)

13

Page 14: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Get the slope of (a,a2) of y=x2

14

Page 15: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

15

Page 16: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

derivative of f(y)=x2

(dp is infinitely small, so)

16

dy/dx=F'(x2)=2x

Page 17: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Rules for basic functionsDerivatives of powers: if

where r is any real number, then

wherever this function is defined. For example, if

then

17

Page 18: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Remember

18

𝑓 ′ (𝑥𝑛)=𝑛𝑥𝑛−1

Page 19: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Leibniz's notation The notation for derivatives introduced by 

Gottfried Leibniz is one of the earliest. It is still commonly used when the equation y = f(x) is

viewed as a functional relationship between dependent and independent variables. Then the first derivative is denoted by

Higher derivatives are expressed using the notation

for the nth derivative of y = f(x) (with respect to x).19

Page 20: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Lagrange's notation Sometimes referred to as prime notation, one of the

most common modern notation for differentiation is due to Joseph-Louis Lagrange and uses the prime mark, so that the derivative of a function f(x) is denoted f′(x) or simply f′.

Similarly, the second and third derivatives are denoted like below.

20

Page 21: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Newton's notation Newton's notation for differentiation, also called the dot

notation, places a dot over the function name to repre-sent a time derivative. If y = f(t), then below expression denote the first derivatives of y with respect to t.

The second derivatives of y with respect to t can be de-noted like this.

21

Page 22: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Application: Tangent vector A Tangent space is a real vector space that intuitively

contains the possible "directions" at which one can tan-gentially pass through x.

The elements of the tangent space are called tangent vectors at x.

22

Page 23: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

23

A pictorial representation of the tangent space of a sin-gle point, x, on a sphere.

Page 24: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Normal mapping To calculate the Lambertian (diffuse) lighting of a sur-

face, the unit vector from the shading point to the light source(L) is dotted with the unit vector normal(N) to that surface, and the result is the intensity of the light on that surface.

• Example of a normal map (center) with the scene it was calculated from (left) and the result when applied to a flat surface (right).

24

Page 25: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Gradient: ∇(read as del or gradient)

In mathematics, the gradient is a generalization of the usual concept of derivative of a function in one dimen-sion to a function in several dimensions. If f(x1, ..., xn) is differentiable, scalar-valued function of standard Cartesian coordinates in Euclidean space, its gradient is the vector whose components are the n partial derivatives of f.

25

The Derivation can be extended to more higher

dimensions!

Page 26: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

• In the above two images, the values of the function are repre-sented in black and white, black representing higher values, and its corresponding gradient is represented by blue arrows.

26

Page 27: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

• The gradient of the function f(x,y) = −(cos2x + cos2y)2 depicted as a projected vector field on the bottom plane.

27

Page 28: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

The gradient (or gradient vector field) of a scalar func-tion f(x1, x2, x3, ..., xn) is denoted ∇f or  where ∇ denotes the vector differential operator, del. The notation "grad(f)" is also commonly used for the gradient.

In a rectangular coordinate system, the gradient is the vector field whose components are the partial derivatives of f:

28

Page 29: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

In the three-dimensional Cartesian coordinate system, this is given by

where i, j, k are the standard unit vectors. For example, the gradient of the function

is:

29

Page 30: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Integral

A definite integral of a function can be represented as the signed area of the region bounded by its graph.

30

Page 31: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Integral In mathematics, an integral assigns numbers to func-

tions in a way that can describe displacement, area, vol-ume, and other concepts that arise by combining infini-tesimal data.

Integration is one of the two main operations of calculus, with its inverse, differentiation, being the other.

Given a function f of a real variable x and an interval [a, b] of the real line, the definite integral

is defined informally as the signed area of the region in the xy-plane that is bounded by the graph of f, the x-axis and the vertical lines x = a and x = b.

31

∫𝑎

𝑏

𝑓 (𝑥 )𝑑𝑥

Page 32: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Observation A plane is the collection of infinite lines.

Similarly, a cube is the collection of infinite planes. Cavalieri's principle

32

Page 33: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Practice

33

Write a function that calculate the integration

Approximations to integral of √x from 0 to 1, with 5 ■  (yellow) right endpoint parti-tions and 12 ■  (green) left endpoint partitions

Page 34: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Remember

34

∫𝑎

𝑏

𝑥𝑛𝑑𝑥=¿ 1𝑛+1

𝑥𝑛+1 ¿][ a

b

Page 35: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Calculus The operation of integration is the reverse of differentia-

tion. For this reason, the term integral may also refer to the

related notion of the antiderivative, a function F whose derivative is the given function f.

In this case, it is called an indefinite integral and is writ-ten:

35

constant of integra-tion

∫❑

𝑥𝑛𝑑𝑥=¿ 1𝑛+1

𝑥𝑛+1+𝐶¿

Page 36: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Calculus

36

constant of integra-tion

∫❑

𝑥𝑛𝑑𝑥=¿ 1𝑛+1

𝑥𝑛+1+𝐶¿

Page 37: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Calculus The fundamental theorem of calculus that connects dif -

ferentiation with the definite integral: if f is a continuous real-valued function defined on a closed interval [a, b], then, once an antiderivative F of f is known, the definite integral of f over that interval is given by

37

Page 38: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

38

F'(x2)=2x

∫❑

(2𝑥 )𝑑𝑥=¿ 𝑥2+𝐶 ¿

Page 39: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

39

∫❑

𝑛𝑥𝑛− 1𝑑𝑥=¿ 𝑥𝑛+𝐶 ¿

𝑓 ′ (𝑥𝑛)=𝑛𝑥𝑛−1

Page 40: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

40

𝑛𝑥𝑛− 1

𝑥𝑛 Differentiation Integration

Page 41: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Physics The velocity of an object is the rate of change of its 

position with respect to a frame of reference, and is a function of time.

41

• Kinematic quantities of a classical particle: mass m, position r, velocity v.

Page 42: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Instantaneous velocity Velocity is defined as the rate of change of position with

respect to time, which may also be referred to as the in-stantaneous velocity  to emphasize the distinction from the average velocity.

42

S(t) = S0 + v0tS=vt

S0 v0

v0t

Page 43: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Instantaneous velocity If we consider v as velocity and x as the displacement

(change in position) vector, then we can express the (in-stantaneous) velocity of a particle or object, at any par-ticular time t, as the derivative of the position with re-spect to time:

43

Page 44: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Acceleration Acceleration, in physics, is the rate of change of 

velocity of an object. An object's acceleration is the net result of any and all 

forces acting on the object, as described by Newton's Second Law.

44

v(t) = v0 + atv=at

v0 v1

a=(v1 – v0)/t

Page 45: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Relationship between velocity and acceleration An object's instantaneous acceleration at a point in

time is the slope of the line tangent to the curve of a v vs. t graph at that point.

In other words, acceleration is defined as the deriva-tive of velocity with respect to time:

45

Page 46: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Example of a velocity vs. time graph, and the relation-ship between velocity v on the y-axis, acceleration a (the three green tangent lines represent the values for acceleration at different points along the curve) and displacement s (the yellow area under the curve.)46

Page 47: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Distance, Velocity and Acceleration From bottom to top:• an acceleration

function a(t);• the integral of the accel-

eration is the velocity function v(t);

• and the integral of the velocity is the distance function s(t).

47

Page 48: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Remember

48

Page 49: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Newtos's second law, F=ma In classical mechanics, for a body with constant mass,

the (vector) acceleration of the body's center of mass is proportional to the net force vector (i.e. sum of all forces) acting on it (Newton's second law):

49

Page 50: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Uniform acceleration

Calculation of the velocity difference for a uniform ac-celeration.

50

Page 51: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

51

Integration

Page 52: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Practice Write a Win32 bouncing ball program. Initial position is (100,100) and initial velocity is (10,-10). Initial acceleration is (0,0). The ball must bounced in the boundaries of client area.

52

Page 53: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks

Practice2 Add external acceleration when direction keys are press-

ing.if( ::GetAsyncKeyState( VK_LEFT ) ) { acceleration = acceleration + KVector( -100, 0, 0 ); bAccelModified = true;}//if

53

Page 55: Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks