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

Length and squared length

Like vectors, the squared length of a quaternion is the same as the dot product of the quaternion with itself. The length of a quaternion is the square root of the square length:

  1. Implement the lenSq function in quat.cpp and declare the function in quat.h:

    float lenSq(const quat& q) {

      return q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;

    }

  2. Implement the len function in quat.cpp. Don't forget to add the function declaration to quat.h:

    float len(const quat& q) {

      float lenSq = q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w;

      if (lenSq< QUAT_EPSILON) {

         return 0.0f;

      }

      return sqrtf(lenSq);

    }

Quaternions that represent a rotation should always have a length of 1. In the next section, you will learn about unit quaternions, which always have a length of 1.

主站蜘蛛池模板: 镇宁| 济阳县| 苍南县| 万宁市| 商水县| 永新县| 施甸县| 西乌珠穆沁旗| 康保县| 南阳市| 浙江省| 寿宁县| 纳雍县| 卓资县| 弋阳县| 印江| 侯马市| 台东县| 乐陵市| 绍兴县| 伊春市| 元朗区| 东乡县| 金华市| 汉寿县| 南开区| 常宁市| 额敏县| 怀安县| 宣武区| 海阳市| 集贤县| 镇赉县| 万安县| 诏安县| 巴彦淖尔市| 芮城县| 砚山县| 祁门县| 静乐县| 金川县|