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

Common quaternion operations

Like vectors, quaternions also have component-wise operations. Common

component-wise operations are adding, subtracting, multiplying, or negating

quaternions. Component-wise quaternion multiplication multiplies a quaternion

by a single scalar value.

Since these functions are component-wise, they just perform the appropriate action on similar components of the input quaternions. Implement these functions in quat.cpp and add declarations for each function in quat.h:

quat operator+(const quat& a, const quat& b) {

    return quat(a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w);

}

quat operator-(const quat& a, const quat& b) {

    return quat(a.x-b.x, a.y-b.y, a.z-b.z, a.w-b.w);

}

quat operator*(const quat& a, float b) {

    return quat(a.x * b, a.y * b, a.z * b, a.w * b);

}

quat operator-(const quat& q) {

    return quat(-q.x, -q.y, -q.z, -q.w);

}

These component-wise operations don't have much practical use by themselves. They are the building blocks for building the rest of the quaternion functionality on. Next, you're going to learn about the different ways to compare quaternions.

主站蜘蛛池模板: 沐川县| 余江县| 沈丘县| 望城县| 遂溪县| 志丹县| 乌什县| 多伦县| 闸北区| 拜泉县| 珲春市| 霍邱县| 高邮市| 虎林市| 教育| 翼城县| 军事| 喀喇沁旗| 靖边县| 连州市| 南丹县| 神农架林区| 荔浦县| 佳木斯市| 冀州市| 子洲县| 根河市| 会理县| 逊克县| 虞城县| 苏尼特左旗| 两当县| 岳阳县| 库尔勒市| 安平县| 台前县| 洪江市| 南木林县| 松江区| 连江县| 赣州市|