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

Scaling vectors

When a vector is scaled, it only changes in magnitude, not direction. As with addition and subtraction, scaling is a component-wise operation. Unlike addition and subtraction, a vector is scaled by a scalar, not another vector.

Visually, a scaled vector points in the same direction as the original vector, but it has a different length. The following figure shows two vectors: (2, 1) and (2, 4). Both vectors share the same direction, but the magnitude of the second vector is longer:

Figure 2.4: Vector scaling

Figure 2.4: Vector scaling

To implement vector scaling, multiply every component of the vector by the given scalar value.

Implement the scale function by overloading the * operator in vec3.cpp. Don't forget to add the function declaration to vec3.h:

vec3 operator*(const vec3 &v, float f) {

    return vec3(v.x * f, v.y * f, v.z * f);

}

Negating a vector can be done by scaling the vector by -1. When negating a vector, the vector maintains its magnitude but changes its direction.

主站蜘蛛池模板: 临清市| 武夷山市| 莒南县| 临沭县| 太白县| 海盐县| 苍梧县| 疏附县| 绥芬河市| 勐海县| 游戏| 肇东市| 喀喇沁旗| 牡丹江市| 台州市| 伊春市| 辽源市| 上犹县| 洞口县| 襄樊市| 伊川县| 文成县| 沁水县| 宜兰市| 武定县| 中方县| 东宁县| 兴国县| 资讯 | 汶上县| 梁平县| 乐山市| 宝丰县| 台东市| 古丈县| 衡水市| 电白县| 定襄县| 南川市| 阿荣旗| 利川市|