官术网_书友最值得收藏!

Vector addition

Adding two vectors together yields a third vector, which has the combined displacement of both input vectors. Vector addition is a component-wise operation; to perform it, you need to add like components.

To visualize the addition of two vectors, draw the base of the second vector at the tip of the first vector. Next, draw an arrow from the base of the first vector to the tip of the second vector. This arrow represents the vector that is the result of the addition:

Figure 2.2: Vector addition

To implement vector addition in code, add like components of the input vectors. Create a new file, vec3.cpp. This is where you will define functions related to the vec3 struct. Don't forget to include vec3.h. Overload the + operator to perform vector addition. Don't forget to add the function signature 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);

}

When thinking about vector addition, remember that a vector represents a displacement. When adding two vectors, the result is the combined displacement of both input vectors.

主站蜘蛛池模板: 儋州市| 兴仁县| 怀宁县| 平远县| 天峻县| 阿鲁科尔沁旗| 禹城市| 金门县| 如东县| 克东县| 东城区| 高雄县| 牟定县| 望谟县| 鄯善县| 白玉县| 应城市| 湖口县| 宝应县| 六盘水市| 宜阳县| 北票市| 陕西省| 阳信县| 应用必备| 建宁县| 介休市| 沙洋县| 璧山县| 鹿邑县| 沾益县| 策勒县| 任丘市| 吕梁市| 通化市| 通河县| 万载县| 阆中市| 淳化县| 广河县| 石嘴山市|