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

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.

主站蜘蛛池模板: 宜章县| 疏勒县| 怀宁县| 普兰店市| 滦平县| 昌宁县| 墨竹工卡县| 庄河市| 贡山| 扶余县| 宿州市| 英德市| 辽阳县| 仪征市| 福海县| 扎囊县| 伊宁市| 西昌市| 阳信县| 平阳县| 太仓市| 乌兰县| 台南市| 武山县| 七台河市| 岑溪市| 缙云县| 遵义县| 渭源县| 汉阴县| 加查县| 牙克石市| 易门县| 临江市| 台湾省| 望江县| 师宗县| 山东| 石狮市| 万荣县| 桃源县|