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

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.

主站蜘蛛池模板: 哈密市| 嵩明县| 慈溪市| 航空| 车致| 天峻县| 修武县| 汉源县| 东乡族自治县| 江门市| 麻城市| 岫岩| 孙吴县| 长宁区| 崇礼县| 牡丹江市| 沾化县| 通辽市| 邵阳市| 长治县| 天峨县| 固阳县| 东安县| 新竹市| 淮阳县| 乌兰察布市| 潮州市| 西盟| 晋州市| 色达县| 静宁县| 临汾市| 监利县| 大英县| 南木林县| 于田县| 伽师县| 武定县| 独山县| 黔西县| 凤凰县|