概述
Discover your serendipity. Record your inspirations.
今天介绍3D数学系列的第一个小主题:点积和叉积,前半部分是它们的数学几何基础定义,后半部分是点积在实际生产当中的运用(这里以游戏引擎unreal为例)。更多3D数学系列文章,请见大目录:2022学习计划 | 游戏中的3D数学(理论及其应用),持续更新中...
There are two types of vector products: Dot Product & Cross Product. Compared with cross product which is applied only in 3D, Dot product has more common and usable fields such as graphics, simulation or AI. and it undoubtedly has much more important relatinships to many other operations, such as matrix multiplication, convolution of signals, statistical correlations, Fourier transforms...... Of course, we will illustrate more details about these in the following chapters as well. Now let’s focus on the fundamental definition of dot prdocut and cross product.
Content
【Dot Product/点积】
Mathematically
Geometrically
【Cross Product/叉积】
Geometrically
Best Practice-点积的应用(中文)
蓝图分析(详细讲解)
蓝图优化
思考题
【Dot Product/点积】
- Dot product yields a scalar.
- Dot product is commutative交换律 a·b = b·a
- Dot product distributes over addition分配律. a·(b + c) = a·b + a·c
- Dot product’s scalar multiplication. (k a)·b = k (a·b) = a ·(k b)
Mathematically
The dot product of two vectors is a scalar, which is the sum of the products of corresponding components.
1)Vector dot product. 点积公式
2)Dot product using summation notation. 点积求和公式
3)Whether 2D or 3D, the principles of the summation are the same.
Geometrically
The dot product of two vectors is the magnitude of one times the projection of the second onto the first.★★★
1)dot product as a projection.
The dot product a·b is equal to the signed length of the projection of b onto any line parallel to a, multiplied by the length of a. Notice that the result of a dot product is a scalar, not a vector.
- Assume for the moment that
is a unit vector, and b is a vector of any length. Now take b and project it onto a line parallel to
. Figure 2.17 illustrates the process of this projection.
- Scaling one operand of the dot product.
·(kb) =
= k(
) = k(
)
Here is a very common use of the dot product as a projection. We will make use of these equations several times to compute vectors, so we’d better to remember this.
2) Dot Product Relation to Intercepted Angle
We ca use the angle between the vectors to interpret what the dot product is.
As the figure shows, the cosine of an angle is the ratio of the length of the adjacent leg divided by the length of the hypotenuse.
So, we can use the dot product to classify the relationship between two vectors. And how does the dot product play a role in the game?
if something is looking at something else, or if two things are on the exact same plane basically they're both going in the same direction. that's what you use the dot product node and of course you should normalize it normally as well.
Best Practice (Please see more details below.????)
【Cross Product/叉积】
- Cross product yields a 3D vector.
- Cross product is not commutative.
- Cross product is not associative.
Mathematically, the term “cross” of the product which comes from the symbol used in the notation can’t be omitted. The equation for the cross product is
Geometrically
the cross product yields a vector that is perpendicular to the original two vectors, so generally it can be used for creating a vector which is perpendicular to a plane, triangle, or polygon. The length of is equal to the product of the magnitudes of a and b and the sine of the angle between a and b.
And here is a vital and confusing point about how to distinguish the coordinate spaces or the direction of the cross product quickly. so, mark for this.
Notice that we must align the head of a with the tail of b, to make the clockwise or counterclockwise determination.
Best Practice-点积的应用
点积的应用:材质球的颜色会随着第一人称的视角变换而变换,当对准被赋予了该材质球的模型时,模型呈绿色,没有对准时是其他颜色,如下图GIF。
蓝图分析:(详细讲解)
蓝图优化
当然连完这些,发现其实场景中材质球的变化颜色还是很小,此时我们可以加入Power节点,增加颜色变化。
思考题
留一个问题,为什么这里的Transform vector节点是View Space to World Space呢?这里就是涉及到3D数学的另一个知识点<Multiple coordinate spaces>。
参考资料:
<1> 3D Math primer for Graphics and Game Development. Second Edition.(chapter 2 vectors.)
<2> Dot Product in unreal.https://www.youtube.com/watch?v=sf3jT12pN6o
最后
以上就是兴奋钢笔为你收集整理的学习3D数学的第7天 | Dot Product & Cross Product(内含点积在unreal中的应用)的全部内容,希望文章能够帮你解决学习3D数学的第7天 | Dot Product & Cross Product(内含点积在unreal中的应用)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复