You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CGAL中:将原空间点转对偶线后,如何遍历排列各有界面顶点?

获取CGAL排列中每个有界面的顶点

你的需求是将原空间点转换为对偶空间直线后,提取排列中每个有界面包含的顶点。以下是修改后的完整代码实现,直接替换你代码中的面遍历循环部分即可:

std::vector<Point> points;
read_objects<Point>(filename, std::back_inserter(points));
std::list<X_monotone_curve> dual_lines;
for (const auto& p : points) std::cout << p.x() << " " << p.y() << std::endl;
for (const auto& p : points) dual_lines.push_back(Line(p.x(), -1, -p.y()));
Arrangement arr;
insert(arr, dual_lines.begin(), dual_lines.end());

// 遍历所有面,提取有界面的顶点
for (auto face_iter = arr.faces_begin(); face_iter != arr.faces_end(); ++face_iter) {
    // 跳过无界面
    if (!face_iter->is_bounded()) continue;

    std::cout << "有界面包含的顶点:" << std::endl;
    // 获取面的外边界环的起始半边
    auto curr_halfedge = face_iter->outer_ccb();
    auto start_halfedge = curr_halfedge;
    do {
        // 获取当前半边对应的顶点
        auto vertex = curr_halfedge->source();
        // 输出顶点坐标(或存入容器)
        std::cout << "(" << vertex->point().x() << ", " << vertex->point().y() << ")" << std::endl;
        ++curr_halfedge;
    } while (curr_halfedge != start_halfedge); // 循环直到回到起始半边
}

关键说明:

  • 判断有界面:通过face_iter->is_bounded()方法区分有界/无界面,无界面是排列的外围无限区域,直接跳过。
  • 遍历边界顶点:CGAL的排列面通过**半边环(CCB)**定义边界,调用outer_ccb()获取面的外边界起始半边,然后循环遍历整个环,直到回到起始迭代器。
  • 迭代器处理:你遇到的CGAL::I_Filtered_iterator是CGAL内部封装的迭代器,无需直接操作,通过source()方法从半边获取顶点即可,顶点迭代器的类型为Arrangement::Vertex_const_iterator。

内容的提问来源于stack exchange,提问作者Jarus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 23:45:17