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

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.

主站蜘蛛池模板: 丽江市| 焉耆| 万荣县| 嘉祥县| 西林县| 新绛县| 浦东新区| 蚌埠市| 马公市| 屏山县| 沈阳市| 渝中区| 宁波市| 巴中市| 登封市| 凉山| 秭归县| 峨眉山市| 潜山县| 枣阳市| 黑河市| 铁力市| 额尔古纳市| 从化市| 通江县| 迁安市| 衡山县| 康定县| 驻马店市| 南澳县| 德江县| 平安县| 西乌| 富民县| 象州县| 海兴县| 财经| 谢通门县| 城固县| 绥宁县| 四子王旗|