beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks
TRANSCRIPT
![Page 1: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/1.jpg)
Beginning Direct3D Game Programming:Mathematics Primer
[email protected] of Digital Contents, DongSeo University.
March 2016
![Page 2: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/2.jpg)
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.
![Page 3: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/3.jpg)
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
![Page 4: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/4.jpg)
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
![Page 5: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/5.jpg)
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
![Page 6: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/6.jpg)
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
![Page 7: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/7.jpg)
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
![Page 8: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/8.jpg)
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
![Page 9: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/9.jpg)
9
![Page 10: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/10.jpg)
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
![Page 11: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/11.jpg)
proof
11
![Page 12: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/12.jpg)
a2+b2=c2
If the length of both a and b are known, then c can be calculated as:
12
![Page 13: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/13.jpg)
Summation Notation: Sigma(∑) In mathematics, summation (symbol: ∑) is the addition
of a sequence of numbers; the result is their sum or total.
13
![Page 14: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/14.jpg)
14
![Page 15: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/15.jpg)
Practice Write a function that calculate below equation.
15
![Page 16: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/16.jpg)
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.
![Page 17: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/17.jpg)
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
![Page 18: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/18.jpg)
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.
![Page 19: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/19.jpg)
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
![Page 20: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/20.jpg)
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
![Page 21: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/21.jpg)
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
![Page 22: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/22.jpg)
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
![Page 23: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/23.jpg)
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
![Page 24: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/24.jpg)
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
![Page 25: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/25.jpg)
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.
![Page 26: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/26.jpg)
26
The right-handed Cartesian co-ordinate system indicating the coordinate planes.
• Unity 3D game engine uses LHS.
![Page 27: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/27.jpg)
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).
![Page 28: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/28.jpg)
28
![Page 29: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/29.jpg)
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
![Page 30: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/30.jpg)
π is commonly defined as the ratio of a circle's circumference C to its diameter d:
30
![Page 31: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/31.jpg)
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
![Page 32: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/32.jpg)
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
![Page 33: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/33.jpg)
Practice Write a program that approximately calculate the Pi.
33
![Page 34: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/34.jpg)
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
![Page 35: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/35.jpg)
Tangent line, secant line and chord
35
![Page 36: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/36.jpg)
36
Do you know the difference be-tween angle, degree and ra-dian?
![Page 37: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/37.jpg)
37
![Page 38: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/38.jpg)
38
![Page 39: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/39.jpg)
39
![Page 40: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/40.jpg)
40
![Page 41: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/41.jpg)
41
![Page 42: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/42.jpg)
Pythagorean trigonometric identity
42
![Page 43: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/43.jpg)
How to implement trigonometric functions? Taylor polynomial
43
![Page 44: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/44.jpg)
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
![Page 45: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/45.jpg)
Practice Write a my own Sine function. Use Taylor series formula. Use for-loop to implement Taylor series and tune proper
iteration count.
45
![Page 46: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/46.jpg)
sum and difference formula
46
![Page 47: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/47.jpg)
47
proof: Let's watch the video.
![Page 48: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/48.jpg)
Inverse of trigonometric functions
48
![Page 49: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/49.jpg)
2D Rotation: Do you remember the first question?
49
![Page 50: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/50.jpg)
Practice Write a function gets a rotated position of (x,y) about
theta.
50
![Page 51: Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks](https://reader031.vdocuments.net/reader031/viewer/2022021918/58ae3d561a28abad338b4a11/html5/thumbnails/51.jpg)
References https://en.wikipedia.org/wiki/Pythagorean_theorem https://en.wikipedia.org/wiki/Trigonometric_functions https://www.youtube.com/watch?v=zcEMKv5yIYs
– The derivation of the Sum Identities for Cosine.
51