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

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.

主站蜘蛛池模板: 荣成市| 灵台县| 尚义县| 太康县| 友谊县| 杭锦后旗| 新营市| 普安县| 宜春市| 海门市| 麟游县| 鱼台县| 福清市| 廊坊市| 儋州市| 双辽市| 永靖县| 济阳县| 巴楚县| 漠河县| 都昌县| 玛沁县| 昌图县| 工布江达县| 盐津县| 英德市| 宕昌县| 汉阴县| 深水埗区| 巢湖市| 明光市| 五大连池市| 枣阳市| 桑植县| 鹤山市| 宾川县| 嘉禾县| 苍山县| 哈尔滨市| 彭泽县| 岳阳县|