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

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.

主站蜘蛛池模板: 广汉市| 南乐县| 清流县| 阳朔县| 新津县| 江都市| 韶山市| 潜江市| 连云港市| 望奎县| 河北省| 梅河口市| 图们市| 万全县| 石首市| 池州市| 黔南| 阜南县| 手游| 麻栗坡县| 赤壁市| 常山县| 岳池县| 车险| 南汇区| 罗山县| 南涧| 调兵山市| 沂水县| 察雅县| 延吉市| 资兴市| 青神县| 溧阳市| 湘乡市| 黄冈市| 郯城县| 桦南县| 乐清市| 安阳市| 海南省|