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

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.

主站蜘蛛池模板: 安国市| 于田县| 迭部县| 辽宁省| 尉氏县| 海兴县| 吉木乃县| 武安市| 常德市| 资溪县| 上虞市| 绥德县| 汕头市| 南康市| 松阳县| 贵州省| 南郑县| 樟树市| 察隅县| 沁阳市| 南京市| 陈巴尔虎旗| 衡阳市| 苏尼特左旗| 茶陵县| 怀远县| 霍山县| 延安市| 册亨县| 杨浦区| 吉水县| 丰台区| 扶绥县| 新昌县| 江北区| 广水市| 丽江市| 贵阳市| 宣武区| 东明县| 疏勒县|