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

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.

主站蜘蛛池模板: 贡觉县| 遂川县| 舒兰市| 宜兰市| 台湾省| 高要市| 云安县| 定南县| 全椒县| 获嘉县| 台州市| 乌审旗| 庆阳市| 屏山县| 呼和浩特市| 海林市| 葫芦岛市| 河间市| 镇原县| 林西县| 西贡区| 方城县| 嘉义市| 平定县| 博罗县| 镇巴县| 呼玛县| 宜阳县| 榆林市| 收藏| 柘城县| 类乌齐县| 岑巩县| 昭苏县| 怀远县| 南皮县| 镇沅| 孝义市| 顺义区| 中西区| 南郑县|