- C++ Game Development By Example
- Siddharth Shekar
- 527字
- 2021-06-24 14:26:15
Vector operations
Just like scalar information, vectors can also be added, subtracted and multiplied with each other. Suppose you have two vectors: and and
, with
= (ax, ay, az) and
= (bx, by, bz). In this case, let us see how you will add and subtract these vectors with each other.
When adding the vectors, we add the components individually to give a new vector:
=
+
= ((ax + bx) , (ay + by) , (az + bz ))
Let's now visualize the addition of two vectors in a graph as shown in the following image.
The Z value is kept as 0.0 for convenience:
Here, =(1.0, 0.4, 0.0 ) and
=(0.6, 2.0, 0.0)
So the resultant vector =
+
= (1.0 + 0.6 , 0.4 + 2.0, 0.0 + 0.0)
= (1.6, 2.4 , 0.0)

Vectors are also commutative meaning +
will give the same result as
+
But if we add
to
then in the diagram above the dotted line will go from the tip of the blue arrow to the tip of the red arrow.
Furthermore, in vector subtraction, we subtract the individual components of the vectors to give a new vector:
=
-
= ((ax - bx) , (ay - by) , (az - bz ))
Now let's visualize the subtraction of 2 vectors in a graph as shown in the following image:
Here = (1.0, 0.4, 0.0 ) and
= (0.6, 2.0, 0.0)
So the resultant vector =
-
= (1.0 - 0.6, 0.4 - 2.0, 0.0 - 0.0)
= (0.4, -1.6, 0.0)

If vectors A and B are equal, the result will be a zero vector with all three components being zero.
If =
. This means ax = bx , ay = by , az = bz, then
=
-
= (0, 0, 0)
We can multiply a scalar with a vector. The result is again a vector with each component of the vector multiplied by the scalar.
For example, if A is multiplied by a single value of s we will have the following result:


= s ×(ax, ay, az)
= (s × ax, s × ay, s × az)
If = (3, -5, 7) and s = 0.5 then
= s
is
= (3 × 0.5, -5 × 0.5, 7 × 0.5)
= (1.5, -2.5. 3.5)
- ATmega16單片機(jī)項目驅(qū)動教程
- 深入理解Spring Cloud與實戰(zhàn)
- 電腦軟硬件維修大全(實例精華版)
- 數(shù)字道路技術(shù)架構(gòu)與建設(shè)指南
- 硬件產(chǎn)品經(jīng)理手冊:手把手構(gòu)建智能硬件產(chǎn)品
- 從零開始學(xué)51單片機(jī)C語言
- The Deep Learning with Keras Workshop
- OpenGL Game Development By Example
- 龍芯自主可信計算及應(yīng)用
- 無蘋果不生活:OS X Mountain Lion 隨身寶典
- Wireframing Essentials
- Python Machine Learning Blueprints
- FL Studio Cookbook
- 電腦橫機(jī)使用與維修
- 筆記本電腦芯片級維修從入門到精通(圖解版)