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

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.

主站蜘蛛池模板: 石泉县| 青海省| 清水河县| 武威市| 临江市| 扬中市| 清远市| 平度市| 濮阳市| 华容县| 永胜县| 万山特区| 潼关县| 沈丘县| 汤阴县| 常德市| 旅游| 拉孜县| 竹溪县| 瑞安市| 康乐县| 厦门市| 延寿县| 聊城市| 布尔津县| 永善县| 那坡县| 高雄市| 新乡市| 锦屏县| 磐石市| 泌阳县| 浦北县| 普安县| 华坪县| 城固县| 西乌| 临桂县| 白玉县| 文化| 鲜城|