如何获取3D矢量的剩余轴知道其他两个

How to get the remaining axis of a 3d vector knowing the other two?

本文关键字:其他 余轴知 两个 何获取 获取 3D      更新时间:2023-10-16

我需要获得3D向量的剩余值" v [3]"

我的函数返回其余轴,其他两个作为参数:

static get_remain_axis(const short a, const short b) {
    if (a == 0) {
        if (b == 1)
            return 2;
        else
            return 1;
    }
    else if (a == 1) {
        if (b == 0)
            return 2;
        else
            return 0;
    }
    else {
        if (b == 0)
            return 1;
        else
            return 0;
    }
}

所以我可以这样做:

v[get_remain_axis(a, b)]

但是我需要在此操作中效率,如果可能的话,如果它是原子。

如何更有效地执行此功能?

至少在我阅读内容时,您的轴012。输入是其中两个,您想返回第三个。

假设是这样,这三个数字最多需要3个,因此您可以做:return 3 - (a + b);

相关文章: