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

Retrieving quaternion data

Since a quaternion can be created from an angle and an axis, it's reasonable to expect to be able to retrieve the same angle and axis from the quaternion. To retrieve the axis of rotation, normalize the vector part of the quaternion. The angle of rotation is double the inverse cosine of the real component.

Implement the getAngle and getAxis functions in quat.cpp and add function declarations for both in quat.h:

vec3 getAxis(const quat& quat) {

    return normalized(vec3(quat.x, quat.y, quat.z));

}

float getAngle(const quat& quat) {

    return 2.0f * acosf(quat.w);

}

Being able to retrieve the angle and the axis that defines a quaternion will be needed later for some quaternion operations.

Next, you're going to learn about the component-wise operations that are commonly performed on quaternions.

主站蜘蛛池模板: 门头沟区| 合作市| 岳阳市| 永平县| 石柱| 平塘县| 邵阳县| 涪陵区| 大埔区| 罗山县| 朝阳区| 慈利县| 隆化县| 高要市| 渭源县| 齐齐哈尔市| 甘肃省| 图木舒克市| 浦东新区| 义乌市| 广宁县| 资溪县| 星子县| 修武县| 韶关市| 石渠县| 永清县| 彩票| 安龙县| 乐安县| 长顺县| 罗甸县| 玛沁县| 兴和县| 瓮安县| 克什克腾旗| 泗阳县| 诸暨市| 钟山县| 怀柔区| 清新县|