找到 3D 点的交叉点两个 std::vectors 的最佳方法

The best way to find intersection two std::vectors of 3D points

我想知道是否有办法使用标准库找到两个 3D 点向量的交点。 3D 点是具有 x、y 和 z 的 glm::vec3。 x、y 和 z 是浮点数。

我知道我们可以在一维数组上使用 std::set_intersection。

需要说明的是,我有 2 个向量:

std::vector<Point> v1;
std::vector<Point> v2;

点在哪里:

struct Point {
    glm::vec3 m_position;
    glm::vec2 m_texCoord;
    glm::vec3 m_normal;

    Point() {}

    Point(glm::vec3& pos, glm::vec2& tex, glm::vec3& norm) {
        m_position = pos;
        m_normal = norm;
        m_texCoord = tex;
    }

    Point(glm::vec3& pos, glm::vec3& norm) {
        m_position = pos;
        m_normal = norm;
    }

    Point(glm::vec3& pos) {
        m_position = pos;
    }
};

我想通过 Point.m_position 找到 v1 和 v2 的交集。

感谢您的帮助。

std::set_intersection() 的文档中提到

1) Elements are compared using operator< and the ranges must be sorted with respect to the same.

所以基本上你需要为 Point 提供重载的 operator<(),并在调用 std::set_intersection().

之前对这些向量进行排序