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

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.

主站蜘蛛池模板: 平和县| 信丰县| 南康市| 鸡西市| 上高县| 常德市| 恩平市| 容城县| 阆中市| 格尔木市| 鲁山县| 三门峡市| 神木县| 渭南市| 九龙城区| 融水| 临城县| 黄平县| 于田县| 沧州市| 沙湾县| 通渭县| 桦南县| 宜川县| 开封县| 江城| 渝中区| 潍坊市| 喀喇沁旗| 叶城县| 恩施市| 卓资县| 连州市| 五莲县| 阿图什市| 那坡县| 紫云| 沅江市| 肇源县| 红安县| 托里县|