[英]The best way to find intersection two std::vectors of 3D points
我想知道是否有一種使用標准庫的方法來查找兩個3D點向量的交集。 3D點是帶有x,y和z的glm :: vec3。 x,y和z為浮點數。
我知道我們可以在1D數組上使用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)使用operator <比較元素,並且必須對范圍進行排序。
因此,基本上,您需要為Point
提供一個重載的operator<()
,並在調用std::set_intersection()
之前對這些向量進行排序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.