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

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.

主站蜘蛛池模板: 蓬安县| 洛扎县| 维西| 桓台县| 漠河县| 丰县| 莒南县| 深圳市| 平果县| 开平市| 沾益县| 克什克腾旗| 虎林市| 新竹市| 万山特区| 潢川县| 高安市| 方城县| 阿拉善右旗| 特克斯县| 宝兴县| 新兴县| 尖扎县| 黑河市| 莫力| 舒城县| 余庆县| 巴青县| 罗田县| 英吉沙县| 霍林郭勒市| 明水县| 平原县| 玛沁县| 台南市| 拜城县| 西宁市| 洛扎县| 偃师市| 铁岭市| 泾源县|