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

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.

主站蜘蛛池模板: 云和县| 永州市| 江都市| 孝义市| 黎平县| 扬州市| 襄城县| 商洛市| 友谊县| 深圳市| 霸州市| 宜黄县| 北安市| 铜山县| 濮阳县| 黄平县| 乐业县| 盈江县| 昭觉县| 赤水市| 梁河县| 浦县| 美姑县| 西华县| 将乐县| 建阳市| 乌兰察布市| 林周县| 麻城市| 霍山县| 彩票| 江达县| 陈巴尔虎旗| 青海省| 柳州市| 诸暨市| 香格里拉县| 孝昌县| 肃北| 咸丰县| 砀山县|