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

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.

主站蜘蛛池模板: 黔东| 邮箱| 京山县| 石渠县| 无为县| 贵溪市| 普陀区| 祁东县| 霍州市| 昔阳县| 海南省| 临夏市| 金寨县| 云南省| 奉化市| 汾阳市| 五原县| 兴山县| 三河市| 济南市| 五家渠市| 阜平县| 龙门县| 庆云县| 翁牛特旗| 浮梁县| 东海县| 基隆市| 宝兴县| 汝南县| 平安县| 峨边| 邹平县| 恩平市| 南澳县| 汶川县| 栾川县| 博湖县| 张家川| 东乡族自治县| 兴安盟|