- Hands-On C++ Game Animation Programming
- Gabor Szauer
- 163字
- 2021-06-30 14:45:50
Vector subtraction
As with adding vectors, subtracting vectors is also a component-wise operation. You can think of subtracting vectors as adding the negative of the second vector to the first vector. When visualized as an arrow, subtraction points from the tip of the second vector to the tip of the first one.
To visually subtract vectors, place both vectors so they share the same origin. Draw a vector from the tip of the second arrow to the tip of the first one. The resulting arrow is the subtraction result vector:

Figure 2.3: Vector subtraction
To implement vector subtraction, subtract like components. Implement the subtraction function by overloading the - operator in vec3.cpp. Don't forget to add the function declaration to vec3.h:
vec3 operator-(const vec3 &l, const vec3 &r) {
return vec3(l.x - r.x, l.y - r.y, l.z - r.z);
}
The steps and logic are very similar to vector addition. It might help to think of vector subtraction as adding a negative vector.
- Python數(shù)據(jù)分析入門與實戰(zhàn)
- Oracle從新手到高手
- 騰訊iOS測試實踐
- C++程序設計基礎教程
- Mastering Ext JS
- Learning SciPy for Numerical and Scientific Computing(Second Edition)
- 0 bug:C/C++商用工程之道
- Mastering Akka
- Kubernetes源碼剖析
- PHP 7從零基礎到項目實戰(zhàn)
- 3ds Max印象 電視欄目包裝動畫與特效制作
- C編程技巧:117個問題解決方案示例
- Shopify Application Development
- 程序員必會的40種算法
- UI動效設計從入門到精通