Files
ViewDesignEngine/include/vde/mesh/delaunay_2d.h
T

48 lines
1.5 KiB
C++
Raw Normal View History

#pragma once
#include "vde/core/point.h"
#include <vector>
#include <array>
namespace vde::mesh {
using core::Point2D;
using core::Point3D;
using core::Vector3D;
/**
* @brief 2D Delaunay 三角化结果
* @ingroup mesh
*/
struct DelaunayResult {
std::vector<Point2D> vertices; ///< 顶点坐标(可能含超级三角形的辅助点)
std::vector<std::array<int, 3>> triangles; ///< 三角形索引(CCW 顺序)
};
/**
* @brief 2D Delaunay 三角化(Bowyer-Watson 增量算法)
*
* 构建点集的 Delaunay 三角化:任意三角形的外接圆内不含其他点。
* 该性质使三角化的最小角最大化,避免狭长三角形。
*
* 算法流程:
* 1. 创建包围所有输入点的超级三角形
* 2. 逐点插入:
* a. 找出外接圆包含新点的所有三角形("坏三角形")
* b. 删除坏三角形,形成多边形空洞
* c. 将新点与空洞边界各边连接形成新三角形
* 3. 删除与超级三角形顶点相关的三角形
*
* @param points 输入 2D 点集(至少 3 个不共线点)
* @return DelaunayResult 三角化结果
*
* @note 时间复杂度:平均 O(n log n),最坏 O(n²)
* @code{.cpp}
* auto result = delaunay_2d({{0,0}, {1,0}, {0.5, 0.5}, {0,1}, {1,1}});
* // result.triangles 为 Delaunay 三角形索引
* @endcode
* @see constrained_delaunay_2d
* @ingroup mesh
*/
DelaunayResult delaunay_2d(const std::vector<Point2D>& points);
} // namespace vde::mesh