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

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.

主站蜘蛛池模板: 海宁市| 宜川县| 嘉善县| 鹰潭市| 长子县| 武邑县| 读书| 同德县| 云安县| 金湖县| 新邵县| 铁岭市| 焦作市| 永平县| 海宁市| 纳雍县| 临猗县| 沂南县| 阿克陶县| 婺源县| 昭通市| 兰西县| 祁东县| 阳高县| 于都县| 仙桃市| 班玛县| 洛川县| 尼勒克县| 芦溪县| 丹棱县| 冷水江市| 公安县| 石狮市| 神池县| 泸定县| 山东省| 黄浦区| 嘉义市| 都匀市| 磐安县|