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

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.

主站蜘蛛池模板: 清原| 高雄县| 合水县| 鞍山市| 调兵山市| 琼结县| 蒙城县| 顺平县| 彭山县| 翼城县| 大悟县| 天津市| 房山区| 马鞍山市| 桂平市| 台东县| 阿鲁科尔沁旗| 元谋县| 怀仁县| 潢川县| 丰都县| 石泉县| 香河县| 正阳县| 襄汾县| 黑龙江省| 蓬溪县| 宕昌县| 开阳县| 册亨县| 永兴县| 鸡东县| 两当县| 巴青县| 商城县| 股票| 芒康县| 黄浦区| 修文县| 酒泉市| 临夏市|