- 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.
- Design Principles for Process:driven Architectures Using Oracle BPM and SOA Suite 12c
- INSTANT OpenCV Starter
- Vue.js 3.x從入門到精通(視頻教學版)
- 從程序員到架構師:大數據量、緩存、高并發、微服務、多團隊協同等核心場景實戰
- C語言程序設計
- jQuery從入門到精通 (軟件開發視頻大講堂)
- Processing互動編程藝術
- Linux環境編程:從應用到內核
- 用戶體驗增長:數字化·智能化·綠色化
- 從零開始學C語言
- QPanda量子計算編程
- Maven for Eclipse
- Python面試通關寶典
- LabVIEW數據采集(第2版)
- Visual C++網絡編程教程(Visual Studio 2010平臺)