Location>code7788 >text

3D Math Fundamentals: graphics and game development (2nd edition) - book notes (1)

Popularity:328 ℃/2024-10-27 21:55:28

Synopsis:

清华大学出版社-图书详情-《3D数学基础:图形和游戏开发(第2版)》

This book is an introductory textbook on 3D math, geometry and algebra in three-dimensional space. It aims to show you how to use math to describe objects in three dimensions and their positions, orientations, and trajectories. This is not a book about computer graphics, simulation, or even computational geometry, but the reader will certainly need the information here if he or she intends to study these subjects.

This is an appropriate book for video game program developers. While the book assumes that most readers are learning to write video games, we expect a broader audience and have designed the body of the book with a diverse audience in mind. If you are a program developer or interested in learning how to make video games, feel free to join! If you don't meet those criteria, then you can still gain a lot here.

Every effort has been made to make this book useful for designers and technical artists as well. Although there are some code snippets in this book, they are easy to read (hopefully) even for non-program developers. Most importantly, while you need to understand the concepts involved before you can understand the code, the reverse doesn't hold true. We use code examples to illustrate how ideas can be realized on a computer, rather than explaining the ideas themselves.

Chapter 1: Cartesian Coordinate Systems

1.1 One-dimensional mathematics

image-20241027173457004

Natural Number : A set of non-negative integers characterized by order and infinity.

Because of the need for numbers in daily life, natural numbers were created first, which are mentioned here as "the number of dead sheep".

Integer : Integers are composed of natural numbers and their negative counterparts.

Because of the development of production and life, the generation of economic activities, gradually began to have poverty, indebtedness, borrowing and lending needs, and so on, and so on the basis of natural numbers to expand to the whole number.

** Rational numbers: integers and fractions **

By then expanding on the whole numbers, such as having to buy half a sheep, and expanding into the realm of fractions, the number range is expanded from whole numbers to rational numbers.

Real Number : Includes rational and irrational numbers.

Sometimes values are encountered that cannot be accurately represented in real terms, typically such as Π (pi).

What we need to know is that rational numbers are countable (i.e., can correspond one-to-one with natural numbers), but real numbers are uncountable.

The study of natural numbers and integers is calledDiscrete Mathematics

The study of real numbers is calledContinuous Mathematics

The real world is discrete. How does this affect designers of 3D computer-generated virtual reality? By their very nature, computers are discrete and finite, and are more likely to encounter the results of discrete and finite nature in the creative process rather than in the real world.

These numbers can be of type short, int, float and double.

Types of variables used in discrete mathematics in computers:

  • short: short is a 16-bit integer that can store 65536 different values.
  • int: int is a 32-bit integer that can store up to 4,294,967,296 different values
  • float: A float is also a 32-bit value that can storesubset of rational numbers (math.)(Slightly less than 4294967296, where the details don't matter).
  • double: double is similar to float, but it uses 64 bits instead of 32.

The first law of computer graphics:

If it looks right, it's right.

1.2 Two-dimensional Cartesian space (flat space)

image-20241027173655118

  • Every two-dimensional Cartesian coordinate space has a special location, called the origin, which is the "center" of the coordinate system, with coordinates (0, 0).
  • Every two-dimensional Cartesian coordinate space has two lines passing through the origin. Each line is called an axis (Axis) and can extend infinitely in two opposite directions.
  • The two axes are perpendicular to each other (actually, they don't necessarily have to be perpendicular, but most common systems we've seen will have vertical axes).

Describes coordinate positions in a two-dimensional coordinate system:

image-20241027174248767

In two dimensions, two numbers can be used to specify a position (in fact, the use of two numbers to describe the position of a point is why it is called two dimensions or two-dimensional space. In three dimensions or three-dimensional space, the use of three numbers is required). In the example of (2,4), the first coordinate (i.e., 2) is called the x-coordinate; the second coordinate (i.e., 4) is called the y-coordinate.

Note that a vertical grid line consists of all points with the same x coordinate; in other words, a vertical grid line (actually any vertical line) marks the line of constant x. Similarly, horizontal grid lines mark lines of constant y. That is, all points on the line have the same y coordinate. When discussing polar coordinate space, this point needs to be recalled a little.

1.3 Three-dimensional Cartesian space

1.3.1 Adding new dimensions and axes

image-20241027174613432

In 3D, we need 3 axes to create a coordinate system. The first two axes are called the x-axis and the y-axis, just like in 2D (of course, it is inaccurate to say that they are the same as the 2D axes, which will be explained in more detail later). We will refer to the third axis (predictably) as the z-axis. In general, we set it up so that all the axes are perpendicular to each other, i.e., each axis is perpendicular to the others.

In three dimensions, any pair of axes defines a plane that contains two axes and is perpendicular to a third. Similarly, the xz plane is perpendicular to the y-axis and the yz plane is perpendicular to the x-axis. We can think of any of these planes as our own two-dimensional Cartesian coordinate space.

1.3.2 Specifying a position in three-dimensional space

image-20241027174835768

In 3D, points are specified using 3 numbers x, y and z. These numbers give signed distances in the yz, xz and xy planes respectively.

The distance will be measured along a straight line parallel to the axis. For example, the x-value is the signed distance to the yz-plane, measured along a line parallel to the x-axis.

1.3.3 Left-handed and right-handed coordinate spaces

All two-dimensional coordinate systems are in some sense "equal.", for any two two-dimensional coordinate spaces A and B, it is possible to rotate coordinate space A so that +x and +y point the same way as they do in coordinate space B (assuming the axes are perpendicular).

The 3D coordinate system has two weeks of coordinate types:

left-handed (Left-Handed) coordinate space and right-handed (Right-Handed) coordinate space.

If two coordinate spaces have the same Handedness, it is possible to rotate them so that the axes are aligned; if the two coordinate spaces have opposite Handedness, then this is not possible.

image-20241027175233692

This is a left-handed coordinate system in three dimensions.

image-20241027175307518

This is a right-handed space coordinate system.

Left- and right-handed coordinate systems also differ in the definition of "positive rotation".

Suppose there is a line in space around which we need to rotate by a specified angle, call this line the axis of rotation. First we must define the direction in which the axis is "pointing", and based on that we can specify the positive direction of rotation.

image-20241027175801993

In the left-handed coordinate system, positive rotation is Clockwise when viewed from the positive end of the axis.

And in the right-handed coordinate system, forward rotation is counterclockwise (Counterclockwise) rotation.

1.4 Some fragmented knowledge

Summation Notation

image-20241027180300524

To obtain the product of a series of values, a similar representation can be used:

image-20241027180406453

interval sign (math.)

\[[a,b] <==> a \le x \le b \]

\[(a,b) <==> a < x <b \]

Angles, degrees and radians

Degree : 360 degrees for one week

Radian: the length of the segment of the arc for which the degree is measured.

image-20241027181939553

trigonometric function

Use the unit circle to define trigonometric functions:

image-20241027182058267

In 2D, if you start with a unit line pointing at +x and then rotate that line counterclockwise by an angle of 0, you can draw that angle at Standard Position (or rotate the line in the other direction if that angle is negative).

image-20241027182336159

The (x,y) coordinates of the endpoints of the lines thus rotated have special properties and are so mathematically important that they are given special functions called the cosine (cosine) and sine (sine) of the angle, defined as follows.

image-20241027182248714

The definitions of secant, cosecant, tangent and cotangent can be continued on the basis of the sine and cosine functions

\[Secant: sec \theta = \frac{1}{cos\theta}, Tangent: tan\theta = \frac{sin\theta}{cos\theta}, Cotangent: csc\theta = \frac{1}{sin\theta}, Cotangent: cot\theta = \frac{1} {tan\theta}=\frac{cos\theta}{sin\theta} \]

image-20241027183655226

Than the relationship, keeping in mind the Hook Theorem: Hook 3 Strand 4 Chord 5

\[Cosine function: cos\theta = \frac{x}{r} ,Sine function: sin\theta = \frac{y}{r},Tangent function: tan\theta = \frac{y}{x} \]

\[Secant function: sec\theta = \frac{r}{x},cotangent function: csc\theta = \frac{r}{y},cotangent function: cot\theta = \frac{y}{x} \]

Constant equation between trigonometric functions:

\[sin(-\theta) = -sin\theta ,cos(-\theta) = cos\theta ,tan(-\theta) = - tan\theta \]

\[sin(\frac{\pi}{2} - \theta) = cos\theta, cos(\frac{\pi}{2} - \theta) = sin\theta,tan(\frac{\pi}{2} - \theta) = cot\theta, \]

Pythagorean Theorem: (Pythagorean Theorem)

\[sin^2\theta + cos^2 \theta = 1, 1 + tan^2 \theta = sec^2 \theta, 1+cot^2 \theta = csc^2\theta \]

image-20241027214037165

times the angle formula:

image-20241027214121354

The sine and cosine theorems:

image-20241027214201802

image-20241027214220846