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

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.

主站蜘蛛池模板: 武威市| 宜兴市| 阿克| 惠州市| 团风县| 郧西县| 方正县| 新巴尔虎右旗| 乐业县| 汪清县| 通渭县| 苍梧县| 休宁县| 贵南县| 罗田县| 永嘉县| 报价| 新邵县| 平定县| 海口市| 双鸭山市| 郯城县| 六枝特区| 丰镇市| 文成县| 延津县| 庄浪县| 房产| 木里| 馆陶县| 固始县| 凭祥市| 枝江市| 临汾市| 鄱阳县| 德安县| 西宁市| 承德市| 固阳县| 阜新市| 建湖县|