简体   繁体   English

查找相交的3D点的两个std :: vector的最佳方法

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

I was wondering if there is a way, using standard library, to find an intersection of two vectors of 3D points. 我想知道是否有一种使用标准库的方法来查找两个3D点向量的交集。 3D point is a glm::vec3 with x, y and z. 3D点是带有x,y和z的glm :: vec3。 x, y and z are floats. x,y和z为浮点数。

I know that we can use a std::set_intersection on 1D arrays. 我知道我们可以在1D数组上使用std :: set_intersection。

Just to be clear I have 2 vectors: 为了清楚起见,我有2个向量:

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

where Point is: 点在哪里:

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;
    }
};

I would like to find an intersection of v1 and v2 by Point.m_position. 我想通过Point.m_position找到v1和v2的交集。

Thank you for your help. 谢谢您的帮助。

In the documentation of std::set_intersection() it's mentioned that std::set_intersection()的文档中提到

1) Elements are compared using operator< and the ranges must be sorted with respect to the same. 1)使用operator <比较元素,并且必须对范围进行排序。

So basically you need to provide an overloaded operator<() for Point , and sort those vectors before calling std::set_intersection() . 因此,基本上,您需要为Point提供一个重载的operator<() ,并在调用std::set_intersection()之前对这些向量进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM