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

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.

主站蜘蛛池模板: 乐平市| 陵水| 翼城县| 马龙县| 七台河市| 吉木萨尔县| 阿瓦提县| 股票| 乌恰县| 彝良县| 金川县| 尉犁县| 嵩明县| 伊吾县| 苍梧县| 德惠市| 茶陵县| 三江| 新余市| 鄱阳县| 昌宁县| 滦平县| 仁寿县| 花莲市| 高平市| 高碑店市| 栖霞市| 泗水县| 三明市| 汶川县| 岑巩县| 芜湖市| 屏东县| 正阳县| 比如县| 宝清县| 昌江| 嫩江县| 呈贡县| 天镇县| 潼关县|