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

Vector subtraction

As with adding vectors, subtracting vectors is also a component-wise operation. You can think of subtracting vectors as adding the negative of the second vector to the first vector. When visualized as an arrow, subtraction points from the tip of the second vector to the tip of the first one.

To visually subtract vectors, place both vectors so they share the same origin. Draw a vector from the tip of the second arrow to the tip of the first one. The resulting arrow is the subtraction result vector:

Figure 2.3: Vector subtraction

Figure 2.3: Vector subtraction

To implement vector subtraction, subtract like components. Implement the subtraction function by overloading the - operator in vec3.cpp. Don't forget to add the function declaration 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);

}

The steps and logic are very similar to vector addition. It might help to think of vector subtraction as adding a negative vector.

主站蜘蛛池模板: 巫溪县| 辽宁省| 石城县| 南部县| 灵台县| 盐源县| 五指山市| 襄垣县| 江川县| 永修县| 额尔古纳市| 额济纳旗| 雅安市| 四子王旗| 许昌市| 安多县| 平定县| 杭锦后旗| 龙口市| 同德县| 鸡泽县| 安图县| 洞头县| 化州市| 北流市| 彰化县| 贵州省| 迭部县| 明溪县| 诏安县| 揭阳市| 淄博市| 建宁县| 石景山区| 台东市| 鲁山县| 无为县| 利津县| 丹东市| 鹤庆县| 沈阳市|