Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks

Preview:

Citation preview

Beginning Direct3D Game Programming:Mathematics Primer

jintaeks@gmail.comDivision of Digital Contents, DongSeo University.

March 2016

2D RotationGoal: We want to get the rotated point of (x,y) about theta(θ), (x',y').

2

Assumption: We just know the four fundamental rules of arithmetic.

Domain and codomain In mathematics, the codomain or target set of a 

function is the set Y into which all of the output of the function is constrained to fall. It is the set Y in the nota-tion y = f(x).

A function f from X to Y. The large blue oval is Y which is the codomain of f . The smaller oval inside Y is the image of f3

Exponentiation Exponentiation is a 

mathematical operation, writ-ten as bn, involving two num-bers, the base b and the exponent n.

When n is a positive integer, exponentiation corresponds to repeated multiplication of the base: that is, bn is the product of multiplying n bases:

4

Factorial In mathematics, the factorial of a non-negative integer

 n, denoted by n!, is the product of all positive integers less than or equal to n.

5

Square Root In mathematics, a square root of a number a is a num-

ber y such that y2 = a, in other words, a number y whose square(the result of multiplying the number by itself, or y × y) is a. 

For example, 4 and −4 are square roots of 16 because 42 = (−4)2 = 16.

6

16 = 42

Cubic Root A Root is a general notation for all degrees.

In case of square root, we can omit superscript 2.

7

27 = 3

3

16 = 42

Inverse function In mathematics, an inverse func-

tion is a function that "reverses" another function. That is, if f is a function mapping x to y, then the inverse function of f maps y back to x.

8

9

Pythagoras' theorem In mathematics, the Pythagorean theorem, also

known as Pythagoras' theorem, is a fundamental rela-tion in Euclidean geometry among the three sides of a right triangle.

a2+b2=c2

10

proof

11

a2+b2=c2

If the length of both a and b are known, then c can be calculated as:

12

Summation Notation: Sigma(∑) In mathematics, summation (symbol: ∑) is the addition

 of a sequence of numbers; the result is their sum or total. 

13

14

Practice Write a function that calculate below equation.

15

Cartesian coordinate system

A Cartesian coordinate system is a coordinate system that specifies each point uniquely in a plane by a pair of numerical coordinates, which are the signed distances to the point from two fixed perpendicular directed lines, measured in the same unit of length.16

• The invention of Cartesian coordinates in the 17th century by René Descartes (Latinized name: Cartesius) revolution-ized mathematics.

Cartesian coordinate system Each reference line is called

a coordinate axis or just axis of the system, and the point where they meet is its origin, usually at ordered pair (0, 0).

The coordinates can also be de-fined as the positions of the perpendicular projections of the point onto the two axes, ex-pressed as signed distances from the origin.

17

Illustration of a Cartesian co-ordinate plane. Four points are marked and labeled with their coordinates: (2,3) in green, (−3,1) in red, (−1.5,−2.5) in blue, and the origin (0,0) in purple.

18

Cartesian coordinate system with a circle of radius 2 cen-tered at the origin marked in red. The equation of a circle is (x− a)2 + (y − b)2 = r2 where a and b are the coordinates of the center (a, b) and r is the radius.

Three dimensions Choosing a Cartesian

coordinate system for a three-dimensional space means choosing an ordered triplet of lines (axes) that are pair-wise perpendicular, have a single unit of length for all three axes and have an orientation for each axis. 

19

Notations and conventions The Cartesian coordinates of a point are usually written

in parentheses and separated by commas, as in (10, 5) or(3, 5, 7).

The origin is often labelled with the capital letter O. In analytic geometry, unknown or generic coordinates

are often denoted by the letters (x, y) in the plane, and (x, y, z) in three-dimensional space.

20

Quadrants The axes of a two-dimen-

sional Cartesian system di-vide the plane into four infi-nite regions, called quadrants, each bounded by two half-axes.

These are often numbered from 1st to 4th and denoted by Roman numerals: I (where the signs of the two coordinates are +,+), II (−,+), III (−,−), and IV (+,−).

21

Cartesian formulae for the plane: distance The Euclidean distance between two points of the plane

with Cartesian coordinates (x1,y1) and (x2,y2) is like be-low:

In three-dimensional space, the distance between points  (x1,y1,z1) and (x2,y2,z2) is

22

Translation and Rotation Translating a set of points of the plane, preserving the

distances and directions between them, is equivalent to adding a fixed pair of numbers (a, b) to the Cartesian coordinates of every point in the set.

To rotate a figure counterclockwise around the origin by some angle  is equivalent to replacing every point with coordinates (x,y) by the point with coordinates (x',y'), where

23

Affine Transformation Another way to represent coordinate transformations in

Cartesian coordinates is through affine transformations. In affine transformations an extra dimension is added

and all points are given a value of 1 for this extra di-mension.

The advantage of doing this is that point translations can be specified in the final column of matrix A. In this way, all of the euclidean transformations become trans-actable as matrix point multiplications.

The affine transformation is given by:

24

Orientation and handedness Once the x- and y-axes are specified, they determine

the line along which the z-axis should lie, but there are two possible directions on this line.

The two possible coordinate systems which result are called 'right-handed' and 'left-handed'.

25

• The left-handed orientation is shown on the left, and the right-handed on the right.

26

The right-handed Cartesian co-ordinate system indicating the coordinate planes.

• Unity 3D game engine uses LHS.

Write a program that draws f(x)=x2

void OnDraw( HDC hdc ) { SelectObject( hdc, GetStockObject( DC_PEN ) ); SetDCPenColor( hdc, RGB( 255, 0, 0 ) ); MoveToEx( hdc, 0, 0, NULL ); LineTo( hdc, 100, 50 );}

27

Use Win32 Gdi application on Windows7. We assume origin is located at (200,200) in the screen

coordinates. Draw the x-axis with a red line. Draw the y-axis with a blue line. 20 pixel corresponds to 1 unit(real number).

28

Pi(π) The number π is a mathematical constant, the ratio of a 

circle's circumference to its diameter, commonly ap-proximated as 3.14159.

It has been represented by the Greek letter "π" since the mid-18th century, though it is also sometimes spelled out as "pi" (/paɪ/).

29

π is commonly defined as the ratio of a circle's circumference C to its diameter d:

30

Radian The radian is the standard unit of angular measure,

used in many areas of mathematics. An angle's mea-surement in radians is numerically equal to the length of a corresponding arc of a unit circle; one radian is just under 57.3 degrees.

31

Computing Pi Monte Carlo methods, which evaluate the results of mul-

tiple random trials, can be used to create approxima-tions of π.

Draw a circle inscribed in a square, and randomly place dots in the square. The ratio of dots inside the circle to the total number of dots will approximately equal π/4.

32

Practice Write a program that approximately calculate the Pi.

33

Trigonometric functions In mathematics, the trigonometric functions (also

called the circular functions) are functions of an angle. They relate the angles of a triangle to the lengths of its

sides.

34

Tangent line, secant line and chord

35

36

Do you know the difference be-tween angle, degree and ra-dian?

37

38

39

40

41

Pythagorean trigonometric identity

42

How to implement trigonometric functions? Taylor polynomial

43

The sine function (blue) is closely approximated by its Taylor polynomial of degree 7 (pink) for a full cycle cen-tered on the origin.

44

Practice Write a my own Sine function. Use Taylor series formula. Use for-loop to implement Taylor series and tune proper

iteration count.

45

sum and difference formula

46

47

proof: Let's watch the video.

Inverse of trigonometric functions

48

2D Rotation: Do you remember the first question?

49

Practice Write a function gets a rotated position of (x,y) about

theta.

50