求线段交点及每个交点的交点线段列表
Find intersection point of segments and list of intersected segments for each intersection point
我试图使用CGAL从2D中的段列表中找出"所有交点"answers"每个交点的相交段"。出于某些原因,我想使用Bentley-Ottmann算法。CGAL库有一个称为swepline 2的算法的c++实现,但有了这个,我只能找到交叉点。在CGAL中是否存在其他实现?或者我如何解决这个问题?
Edit:真正快速的解决方法是使用Sweep line 2生成所有交点,循环遍历所有生成的交点,并为每个交点记录该点的坐标和包含该点的所有线段到您选择的结构中。
一个快速的解决方案(虽然不是最有效的)是:
//Probably start off with a struct to store your information
struct intersection{
//This stores the x and y position of the intersection.
int[2] xyCoords;
//This stores the segment ids or indexes of the intersection line segments.
//For example, if the 1st and 5th line segment intersect, you would store 1 and 5 in here.
int[2] segmentIDs;
}
然后创建一个交集结构的向量,这样你就可以存储所有不同的交集。
vector<intersection> intersectionVector;
然后循环遍历所有线段,类似于以下内容:
for (int i = 0; i < numSegments; i++){
for (int j = 0; j < numSegments; j++){
//Don't look at the same points.
if (i == j)
continue;
//See below for pseudocode for this part.
}
}
现在要填充那个块,而不是重新发明任何东西,只需参考如何检测两条线段相交的位置?
如上一环节所示,计算r × s和(q−p) × r的值,其中x为向量叉积。从这里开始,如果您关心细节,只需使用if/else块来说明四种情况(ctrl f表示"现在有四种情况:")。如果你只是想要你在问题中概述的东西,只要检查情况3的有效性。如果它是有效的,将线段的索引以及x和y坐标存储在矢量/你正在使用的任何结构中。
您需要做的唯一额外的事情是使用compute u并将其应用于您正在检查的两条线段的第二条线段,以存储交点的xy坐标
相关文章:
- 将列表 en 列表迭代器作为指针 C++ 传递
- 无法初始化初始值设定项列表之外的字段
- 如何在逗号分开列表中解析字段并将其转换为整数
- 通过查找一对项目的代码获取错误的输出,在给定的总和相等的给定列表中列表
- 列表STL的时间复杂性在一段时间内进行排序
- C 列表一次由多个字段排序
- 导致IAR ARM中出现错误的成员结构位字段元素的Initializer列表初始化
- C++ 在列表和列表之间选择返回类型<<string>std::p air<string,string>>
- 与内存堆有关的C 链接列表(STD ::列表)是否使用新的
- RCPP:处理包含列表的列表
- 基本STL:向量列表或列表向量,在这种特殊情况下哪个会更好
- 图形、顶点、STL 列表:为什么列表是空的
- 如何定义映射::迭代器的列表和列表::迭代器的映射
- 我如何解码一个列表的列表
- 迭代一对列表,列表在数组中
- 将递增数量的列表子列表存储在vector中
- 在c++中如何像Java那样定义列表的列表或堆栈的列表
- 我如何创建一个稀疏矩阵作为列表的列表?(c++)
- 从字符串列表的列表映射中获取字符串
- 数组列表vs列表