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

Angle axis

Quaternions are often created using an axis of rotation and an angle. A rotation about an axis by θ can be represented on a sphere as any directed arc whose length is on the plane perpendicular to the rotation axis. Positive angles yield a counterclockwise rotation around the axis.

Create a new file, quat.cpp. Implement the angleAxis function in quat.cpp. Don't forget to add the function declaration to quat.h:

#include "quat.h"

#include <cmath>

quat angleAxis(float angle, const vec3& axis) {

    vec3 norm = normalized(axis);

    float s = sinf(angle * 0.5f);

    return quat(norm.x * s,

                norm.y * s,

                norm.z * s,

                cosf(angle * 0.5f)

    );

}

Why ? A quaternion can track two full rotations, which is 720 degrees. This makes the period of a quaternion 720 degrees. The period of sin/cos is 360 degrees. Dividing θ by 2 maps the range of a quaternion to the range of sin/cos.

In this section, you learned how the angle and axis of a rotation are encoded in

a quaternion. In the next section, you will learn how to build an angle and an axis

for the rotation between two vectors and encode that into a quaternion.

主站蜘蛛池模板: 勐海县| 阿克苏市| 池州市| 万全县| 夹江县| 法库县| 许昌市| 临泽县| 泰顺县| 建昌县| 南城县| 勐海县| 武鸣县| 兰州市| 彭水| 南和县| 比如县| 马关县| 原平市| 青浦区| 调兵山市| 社会| 唐山市| 屏山县| 团风县| 盘山县| 富平县| 双峰县| 舞钢市| 正镶白旗| 家居| 龙门县| 浑源县| 花垣县| 偏关县| 乐安县| 得荣县| 海安县| 万安县| 勐海县| 新和县|