Book notes on the essence of game AI programming case-a preliminary study on mathematics and physics

Source: Internet
Author: User
1.1.1 Cartesian coordinate system

In two-dimensional space, the Cartesian coordinate system is defined as two coordinate axes that are Cartesian and marked with unit length. The horizontal axis is called the X axis, while the vertical axis is called the Y axis. The intersection of the two axes is called the origin, as shown in Figure 1.1.

As shown in 1.1, the arrows at each axis endpoint indicate that they are infinitely stretched in each direction. Suppose there is an infinite piece of paper with the X and Y axes on it. The paper represents the XY plane, and all the points in the Cartesian coordinate system can be produced on this plane. A point in a 2D space can be represented by a pair of coordinates (x, y. The values of X and Y represent the distance along their respective axes.

In order to express three-dimensional space, another coordinate axis Z uranium is required. The Z axis extends from the back of your screen to the front of the screen and passes through the origin on the way. 1.2.

1.1.2 FUNCTIONS AND EQUATIONS

The concept of a function is the foundation of mathematics. A function expresses the relationship between two (or more) items called variables and is typically written in the form of an equation (one algebraic expression equals another ).

The left side of Figure 1.3 shows how the X value of the Function Y = 2x is drawn on the XY plane. The range of X value used is-5.0-5.0.

 

In order to make the Function Y = mx + C into a graph, you must first have some values of constants M and C. Let's set m = 2 and C = 3, and give the Function Y = 2x + 3. Figure 1.3 The result graph is displayed on the right.

Y = mx + C is a function that defines all straight lines in a 3D space. Constant M defines the slope of a straight line, or the steep degree of a straight line tilt. constant C specifies the position where the straight line and Y axis intersect.

1.1.2.1 index and power

An exponential function is defined as follows:

Alpha is called the base and X is called the power. If we verbally describe this equation, f (x) is equal to the X power of. This means that a is multiplied by itself X times.

Figure 1.5 shows the graph drawn when the equation is a = 2. The curve clearly shows how the value of Y rapidly increases with the value of X. This type of curve is often referred to as exponential growth.

 

1.1.2.3 simplified equation

Generally, a equation must be simplified first. A golden law for simplification is to obtain the solution of an equation by adding, subtracting, multiplication, or division of some terms on both sides of the equation. (This rule has one exception: When multiplication or division is performed, this item cannot be zero. > As long as the operations on both sides of the equation are the same, the two sides will be equal.

1.1.3 triangle Learning

Angle and radian

An angle is defined as the dispersion of two rays with a common origin, as shown in Figure 1.7.

Radian is a measurement unit based on the unit radius (radius: 1) Circle centered on the origin. The radius of a circle is the distance from the center of the circle to the point on the circumference. In the same graph with two rays (see Figure 1.7) as the unit circle, we get Figure 1.8. The length of the curve segment between two rays (shown as a point line in the figure) is the measurement of their angle in radians.

Degrees to radians: radians = angle X (π/180)

Radian rotation angle: angle = radian X (180/π)

Cut-off Theorem

The square of the oblique edge at the right corner of a right triangle is equal to the sum of the squares of the other two sides. The oblique side of a triangle is its longest side, as shown in Figure 1.10.

 

If the oblique edge is represented by H, the theorem can be written:

Take the square root of the two sides:

 

This means that if we know the length of any two sides of a right triangle, we can easily find the third side.

Cartesian trigonometric function

Sine sin α of α = B/C; (diagonal edges of edges)

Cosine cos α of α = A/C; (adjacent oblique edges)

The tangent of α tan α = B/a; (adjacent edge of the right side)

When an angle is known, a sine, cosine, or tangent function is used to obtain the corresponding trigonometric function value. Otherwise, an inverse trigonometric function is used to calculate the angle.

1.1.4 Vector

One Direction expresses two properties: Direction and size. The right side of 1.16 shows the vector at the molecular origin (9, 6 ).

Vector operations

(The following content comes from the basics of 3D mathematics: graphics and Game Development)

1 zero vector

The zero vector is the unique vector with zero size. Each dimension is zero, and the zero vector is the only vector with no direction. In fact, the zero vector represents"No displacement", Just as the scalar zero represents"No quantity.

Negative vector 1.2

To obtain the negative vector of any dimension vector, simply change each component to a negative one. The mathematical expression is:

Ry explanation: If the vector is negative, a vector with the same size and opposite direction is obtained. (The position of a vector in a graph is irrelevant. Only the size and direction are the most important ).

Vector size 1.3

In fact, the vector size and direction are not explicitly expressed in the mathematical representation of the vector. The size of all vectors needs to be calculated. The vector size is also called the length orModule.

The formula for calculating the n-dimensional vector size is as follows:

In linear algebra, the vector size is expressed by the dual vertical lines on both sides of the vector, which is similar to the absolute value of the scalar by adding a single vertical line on both sides of the scalar.

1.4 scalar and vector multiplication

Although scalar and vector cannot be added, they can be multiplied. The result shows that a vector is parallel to the source vector, but the length is different or in the opposite direction.

Scalar and vector multiplication are very direct. You can multiply each component of a vector by a scalar.

1.5 standardization Vector

For many vectors, We only care about its direction and its size. In this case, it is very convenient to use the unit vector.

A unit vector is a vector with a size of 1, which is often called a standardized vector.

For any non-zero vector V, you can calculate a unit vector V in the same direction as v. This process is called VECTOR standardization. To standardize the vector, divide the vector by its size.

Zero vectors cannot be standardized. This is not allowed in mathematics, because it will lead to division by zero. It also has no significance in ry, because the zero vector has no direction.

1.6 addition and subtraction of Vectors

If the two vectors have the same dimension, they can be added or subtracted. The dimension of the result vector is the same as that of the original vector. Vector addition and subtraction are the same as scalar addition and subtraction.

Add or subtract two vectors and add the corresponding components.

(1) A vector cannot be added or subtracted from a scalar or dimension.

(2) Like scalar addition, vector addition satisfies the exchange law, but vector subtraction does not.

1.7 vector point Multiplication

The point multiplication of a vector is also called the inner product of a vector.

The point multiplication of a vector is the sum of the product of the corresponding component, and the result is a scalar.

The dot multiplication result describes the degree of similarity between two vectors. The larger the dot multiplication result, the closer the two vectors are.

1. Determine whether it is vertical. If a · B = 0, a then B.

2. Positive and negative result of the dot multiplication. If a · B <0, then margin> 90 °. If a · B> 0, then margin <90 °, the angle is the angle between vector A and vector B.

3. angle between two vectors. A · B = | A | B | cos cosine, where cosine is the angle between vector A and vector B.

1.8 vector difference Multiplication

The vector cross multiplication is also called the cross product. It can only be applied to 3D vectors.

The cross-multiplication vector is perpendicular to the original two vectors.

C ++ vector encapsulation class:

# Ifndef _ vector3_h __# DEFINE _ vector3_h _ # include <math. h> ////////////////////////////////////// //// // vector3 simple 3D vector class ////// //////////////////////////////////////// //// // class vector3 {public: float x, y, z; // constructor // default constructor. No vector3 () {}// copy const vector3 (const vector3 & ): X (. x), y (. y), Z (. z) {}// the constructor with parameters. initialize vector3 (float NX, float NY, Flo At Nz): X (nx), y (NY), Z (NZ) {}// Standard Object operation // reload the "=" operator vector3 & operator = (const vector3 & A) {x =. x; y =. y; Z =. z; return * This;} // reload the "=" operator bool operator = (const vector3 & A) const {return x =. X & Y =. Y & Z =. z;} // reload the "=" operator bool Operator! = (Const vector3 & A) const {return X! = A. X | y! = A. Y | Z! =. Z;} // Vector Operation // vector returns void zero () {x = y = z = 0.0f;} // reload the unary "-" operator vector3 operator -() const {return vector3 (-X,-y,-y);} // reload the binary "+" and "-" operators vector3 operator + (const vector3 &) const {return vector3 (x +. x, Y +. y, Z +. z);} vector3 operator-(const vector3 & A) const {return vector3 (x-a.x, y-a.y, z-a.z );} // multiplication and division of scalar vector3 operator * (float a) const {return vector3 (x * a, y * a, z * );} vector3 operator/(float a) const {float oneovera = 1.0f/a; return vector3 (x * oneovera, y * oneovera, z * oneovera );} // reload the self-Inverse Operator vector3 & operator + = (const vector3 & A) {x + =. x; y + =. y; Z + =. z; return * This;} vector3 & operator-= (const vector3 & A) {X-=. x; y-=. y; Z-=. z; return * This;} vector3 & operator * = (const vector3 & A) {x * =. x; y * =. y; z * =. z; return * This;} vector3 & operator/= (float a) {float oneovera = 1.0f/a; x * = oneovera; y * = oneovera; z * = oneovera; return * This;} // vector standardization void normailze () {float magsq = x * x + y * Y + z * z; If (magsq> 0.0f) {float oneovermag = 1.0f/sqrtf (magsq); x * = oneovermag; y * = oneovermag; z * = oneovermag;} // vector dot multiplication, overload standard multiplication operator float operator * (const vector3 & A) const {return x *. X + Y *. Y + z *. Z ;}}; //////////////////////////////////////// /// // non-member functions //////////// //////////////////////////////////////// /////////// obtain the vector modulo inline float vectormag (const vector3 &) {return sqrtf (. x *. X +. y *. Y +. z *. z);} // calculate the vector cross-multiplication inline vector3 crossproduct (const vector3 & A, const vector3 & B) {return vector3 (. y * B. z-. z * B. y,. z * B. x-. x * B. z,. x * B. y-. y * B. x);} // implement scalar left multiplication inline vector3 operator * (float K, const vector3 & V) {return vector3 (K * v. x, K * v. y, K * v. z);} // calculate the inline float distance (const vector3 & A, const vector3 & B) {float dx =. x-b.x; float DY =. y-b.y; float DZ =. z-b.z; return sqrtf (dx * dx + dy * dy + DZ * Dz );} //////////////////////////////////////// /// // global variable ///////////// //////////////////////////////////////// ////////// provide a global zero vector extern const vector3 kzerovector; # endif/_ vector3_h __
Physics 1.2

This book defines physics as follows: Science of mass and energy, and the interaction between them. Artificial Intelligence programmers often use the laws of physics to work, especially the laws of physics related to motion, which are introduced in this section.

1.2.1 time

Time is a scalar (its size can be completely determined without direction), measured in seconds, abbreviated as S.

1.2.2 distance

The standard unit of distance (a scalar) is m (meters ).

1.2.3 Quality

Mass is a scalar measured in kilograms, abbreviated as kg. Quality is a measure of the total volume of a thing (excluding external forces ).

1.2.4 location

The position is the property measured relative to the center of the center, and the center of the quality is the equilibrium point of the object. Assume that an object is mounted by a rope at this point, and the object can be balanced at any position. Another
A good way to imagine a centroid is to view it as the balance of all quality in the crop body.

1.2.5 speed

A velocity is a vector (a vector with the size and direction) that expresses the change rate of distance relative to time. The standard unit of measurement speed is MLS (meters per second ). It uses the mathematical formula as follows:

△X indicates a change in distance. The distance at the end minus the distance at the start of movement. Delta t represents a change in speed. The End Time minus the start time.

1.2.6 Acceleration

Acceleration is a vector that expresses the rate of change of speed over a period of time. It is measured in every second of meter and written in Mb/s. Acceleration can be expressed in mathematics as follows:

1.2.7 force

Force is the amount that can change the speed or movement line of an object.

We know that if the force applied to an object is non-zero, an acceleration is generated in the direction of the force. But what is the acceleration? The answer is that the size of acceleration A is inversely proportional to the mass M of the object and is proportional to the applied force F. This relationship can be given in the following formula:

In more cases, you will see the formula as follows:

Using this formula, if we know the acceleration of an object and its quality, we can calculate the force applied to it.

For example, if an object has a mass of 2000 kg and the well has an acceleration of 1.5 Mb/s, the force exerted on it is:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.