22
Beginning Direct3D Game Programming: Mathematics 2 Logarithm [email protected] Division of Digital Contents, DongSeo University. March 2016

Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

Embed Size (px)

Citation preview

Page 1: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

Beginning Direct3D Game Programming:Mathematics 2

[email protected]

Division of Digital Contents, DongSeo University.March 2016

Page 2: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

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:

2

Page 3: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

Logarithm In mathematics, the logarithm is the inverse operation

 to exponentiation. That means the logarithm of a number is the exponent

 to which another fixed value, the base, must be raised to produce that number.

In simple cases the logarithm counts repeated multipli-cation.

For example, the base 10 logarithm of 1000 is 3, as 10 to the power 3 is 1000 (1000 = 10 × 10 × 10 = 103); the multiplication is repeated three times.

3

Page 4: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

The logarithm of x to base b(log base b of x), de-noted logb(x), is the unique real number y such that

by = x. For example, as 64 = 26, we have log2(64) = 6

4

Page 5: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

The graph of the logarithm to base 2 crosses the x axis (horizontal axis) at 1 and passes through the points with coordinates (2, 1), (4, 2), and (8, 3). For example, log2(8) = 3, because 23 = 8. The graph gets arbitrarily close to the y axis, but does not meet or intersect it.5

Page 6: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

A full 3-ary tree can be used to visualize the exponents of 3 and how the logarithm function relates to them.

6

Page 7: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

Product, quotient, power and root

7

Page 8: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

Binary search In computer science, binary search, also known

as half-interval search or logarithmic search,[1] is a search algorithm that finds the position of a target value within a sorted array.

8

Page 9: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

9

: Number of iterations for bi-nary and linear search for n from 1 to 1000.

Page 10: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

Practice Write a binary search program. Use data {1,3,5,7,9,10,15,16}. Print the number of comparison when function finished.

10

Page 11: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

Time complexity In computer science, the time complexity of an 

algorithm quantifies the amount of time taken by an al-gorithm to run as a function of the length of the string representing the input.

The time complexity of an algorithm is commonly ex-pressed using big O notation, which excludes coeffi-cients and lower order terms.

When expressed this way, the time complexity is said to be described asymptotically, i.e., as the input size goes to infinity.

For example, if the time required by an algorithm on all inputs of size n is at most 5n3 + 3n for any n (bigger than some n0), the asymptotic time complexity is O(n3).

11

Page 12: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

Sort Algorithms

12

Page 13: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

Quick sort Quicksort is a fast sorting algorithm, which is used not

only for educational purposes, but widely applied in practice.

On the average, it has O(n log n) complexity, making quicksort suitable for sorting big data volumes. 

13

Page 14: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

Algorithm The divide-and-conquer strategy is used in quicksort. Be-

low the recursion step is described:1. Choose a pivot value. We take the value of the mid-dle element as pivot value, but it can be any value, which is in range of sorted values, even if it doesn't present in the array.2. Partition. Rearrange elements in such a way, that all elements which are lesser than the pivot go to the left part of the array and all elements greater than the pivot, go to the right part of the array. Values equal to the pivot can stay in any part of the array. Notice, that array may be di-vided in non-equal parts.3. Sort both parts. Apply quicksort algorithm recursively to the left and the right parts.

14

Page 15: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

Partition algorithm in detail There are two indices i and j and at the very beginning

of the partition algorithm i points to the first element in the array and j points to the last one.

Then algorithm moves i forward, until an element with value greater or equal to the pivot is found.

Index j is moved backward, until an element with value lesser or equal to the pivot is found.

If i ≤ j then they are swapped and i steps to the next position (i + 1), j steps to the previous one (j - 1).

Algorithm stops, when i becomes greater than j. After partition, all values before i-th element are less or

equal than the pivot and all values after j-th element are greater or equal to the pivot.

15

Page 16: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

example Sort {1, 12, 5, 26, 7, 14, 3, 7, 2} using quicksort.

16

Page 17: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

17

Page 18: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

Practice Write a Quick sort function.

18

Page 19: Beginning direct3d gameprogrammingmath02_logarithm_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.

19

Page 20: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

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

20

Page 21: Beginning direct3d gameprogrammingmath02_logarithm_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.

21

Page 22: Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks

References https://en.wikipedia.org/wiki/Logarithm

22