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

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.

主站蜘蛛池模板: 永兴县| 渑池县| 南城县| 嘉兴市| 陕西省| 安徽省| 榆林市| 白山市| 定南县| 美姑县| 吐鲁番市| 辽阳市| 新丰县| 三穗县| 皋兰县| 富川| 云梦县| 东莞市| 田阳县| 汉源县| 屯昌县| 淄博市| 双鸭山市| 海盐县| 阿巴嘎旗| 东丽区| 华池县| 沙坪坝区| 龙门县| 闸北区| 皋兰县| 深水埗区| 镇雄县| 鄄城县| 房产| 莱阳市| 隆化县| 阳春市| 香港 | 南开区| 安乡县|