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

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.

主站蜘蛛池模板: 繁峙县| 五大连池市| 特克斯县| 宜都市| 靖边县| 筠连县| 乃东县| 体育| 洪洞县| 沁水县| 常熟市| 吉水县| 肥西县| 南开区| 综艺| 昆明市| 丹寨县| 崇左市| 茂名市| 黑龙江省| 寿宁县| 洛浦县| 遂溪县| 顺义区| 惠水县| 龙游县| 台中市| 随州市| 寻甸| 巫山县| 运城市| 北流市| 康保县| 扬中市| 东明县| 商南县| 江门市| 新源县| 香河县| 灵璧县| 台山市|