Vector operations

Several mathematical operations can be done with vectors. Understanding these operations is fundamental to manipulating objects in 3D space:

  • Vector addition: The sum of two vectors is determined by adding each of their elements. The next example shows the sum of vectors (3, 5, 0) and (5, 2, 0):
V1 = (3, 5, 0)
V2 = (5, 2, 0)
V1 + V2 = (3 + 5, 5 + 2, 0 + 0)
V1 + V2 = (8, 7, 0)

The following diagram is a graphical representation of the previous example of vector addition:

The following screenshot shows the vector addition node:

  • Vector subtraction: The subtraction of one vector from another is determined by subtracting each of its elements. This is an example of vector subtraction using the vectors (6, 8, 0) and (1, 4, 0):
V1 = (6, 8, 0)
V2 = (1, 4, 0)
V1 – V2 = (6 – 1, 8 – 4, 0 – 0)
V1 – V2 = (5, 4, 0)

The following diagram is a graphical representation of the previous example of vector subtraction :

The vector subtraction node is shown in the following screenshot:

  • Length of a vector: The length (or magnitude) of a vector can be used to represent the distance between two points. It can be calculated using the Blueprint node of the next screenshot:

  • Normalizing vectors: We use vector normalization to find a unit vector. The unit vector has a length equal to one. It is often used when direction needs to be indicated. There is a node named Normalize that receives a vector as input and returns the normalized vector:

  • Scalar vector multiplication: An integer or float number is also known as a scalar value. The multiplication of a vector by a scalar value is done by multiplying each of its elements by the scalar value. This operation changes the length of the vector, but the direction remains the same unless the scalar is negative, in which case, the vector will point in the opposite direction after the multiplication:

  • Dot product: The dot product is a projection of one vector onto another vector. The dot product of two normalized vectors is equal to the cosine of the angle formed between the vectors and can range from -1.0 to 1.0:

The dot product can be used to verify the relationship between two vectors, such as whether they are perpendicular or parallel. The following diagram shows some examples of a dot product between two vectors, A and B:

  • Actor vectors: Some Functions return the forward, right, and up vectors of an Actor. The returned vectors are normalized (length = 1). The following screenshot shows these Functions, which are often used to direct movement:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset