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

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.

主站蜘蛛池模板: 杭州市| 新营市| 舞阳县| 盐城市| 昆明市| 乐都县| 富锦市| 韩城市| 昌乐县| 新泰市| 潮安县| 桐城市| 玛纳斯县| 丘北县| 梧州市| 天祝| 磐安县| 滨州市| 黄石市| 资阳市| 邢台县| 海阳市| 海阳市| 镇平县| 崇仁县| 行唐县| 乌审旗| 泰顺县| 天气| 山西省| 小金县| 大丰市| 桂林市| 茌平县| 齐河县| 中阳县| 融水| 禄劝| 宣汉县| 彭州市| 砚山县|