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

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.

主站蜘蛛池模板: 永兴县| 紫云| 呈贡县| 西乌珠穆沁旗| 拜泉县| 绥宁县| 丰都县| 阿克陶县| 上虞市| 白山市| 交城县| 灵寿县| 轮台县| 得荣县| 神农架林区| 汉源县| 龙里县| 古蔺县| 阳新县| 大田县| 运城市| 思茅市| 高安市| 辽阳县| 周口市| 赣榆县| 洛扎县| 屏南县| 左贡县| 苍山县| 珲春市| 敦煌市| 石台县| 余庆县| 隆林| 新乡县| 海淀区| 兴山县| 拜城县| 皋兰县| 屏东市|