[UE Material] Commonly used vector operation nodes - dot product, cross product, normalization

Table of contents

1. Dot product

Two, cross product

3. Normalization


1. Dot product

        The dot product, also known as the inner product or scalar product, is an operation used to compute the relationship between two vectors. For two three-dimensional vectors A(a1,a2,a3) and B(b1,b2,b3), their dot product can be expressed by the following formula:

A B = a1​⋅b1​+a2​⋅b2​+a3​⋅b3​

In UE, the dot product operation can be used to judge the directional relationship between two vectors:

(1) The directions are the same, and the dot product result is 1

As shown in the figure, two parallel three-dimensional vectors along the Z-axis direction, the result of the dot product operation is 1

(2) The direction is vertical, and the dot product result is 0

As shown in the figure, two three-dimensional vectors perpendicular to each other, the result of the dot product operation is 0

(3) The direction is reversed, and the dot product result is -1

As shown in the figure, the result of the dot product operation for two 3D vectors in opposite directions is -1. Since the color range is 0~1, black is still displayed here.

Two, cross product

        Cross product, also known as outer product or vector product, is an operation used to compute the relationship between two vectors, resulting in a new vector. For two three-dimensional vectors A(a1,a2,a3) and B(b1,b2,b3), their cross product can be expressed by the following formula:

A×B=(a2​b3​−a3​b2​,a3​b1​−a1​b3​,a1​b2​−a2​b1​)

In UE, the cross product operation can obtain the operation of the third axis through two known axes

As shown in the figure, (1,0,0)×(0,1,0)=(0,0,1), the result is blue

3. Normalization

        Normalization is to scale a vector or value so that its length (modulus) is equal to 1, thereby converting it into a unit vector or normalized value. 

        For the vector a, record |a| as the modulus length of a, |a| = (the result of adding the second power of each component of the vector a) to the square root, and the normalization of the vector a is recorded as a^ , after normalization a^ is also called  the unit vector of vector a . The formula is as follows

a^ = a / |a|

In UE, the vector after the normalization operation only retains the direction information of the vector, and the length of the vector can be uniformly set to 1

As shown below, (10,0,0) will emit a very bright red light

 After normalization, it is reduced to (1,0,0)

Guess you like

Origin blog.csdn.net/ChaoChao66666/article/details/132595515