ViewDesignEngine  3.1.0
高性能 CAD 计算几何引擎
曲线曲面模块 (vde::curves)

Bézier、B-Spline、NURBS 曲线与曲面的求值、求导、细分 更多...

class  vde::curves::BezierCurve
 任意阶 Bézier 曲线 更多...
 
class  vde::curves::BezierSurface
 Bézier 张量积曲面 更多...
 
class  vde::curves::BSplineCurve
 B 样条曲线(非有理、均匀/非均匀节点) 更多...
 
class  vde::curves::BSplineSurface
 B 样条张量积曲面(非有理) 更多...
 
class  vde::curves::NurbsCurve
 NURBS 曲线(Non-Uniform Rational B-Spline) 更多...
 
class  vde::curves::NurbsSurface
 NURBS 张量积曲面 更多...
 

函数

NurbsSurface vde::curves::offset_surface (const NurbsSurface &surf, double distance)
 NURBS 曲面等距偏移 更多...
 
NurbsSurface vde::curves::trim_surface (const NurbsSurface &surf, double u_min, double u_max, double v_min, double v_max)
 NURBS 曲面参数域裁剪 更多...
 
NurbsSurface vde::curves::blend_surfaces (const NurbsSurface &surf_a, const NurbsSurface &surf_b, int edge_a, int edge_b, double blend_radius)
 两 NURBS 曲面沿边界边的过渡面 更多...
 
NurbsSurface vde::curves::ruled_surface (const NurbsCurve &curve_a, const NurbsCurve &curve_b)
 两 NURBS 曲线间的直纹面 更多...
 
NurbsSurface vde::curves::coons_patch (const NurbsCurve &curve_u0, const NurbsCurve &curve_u1, const NurbsCurve &curve_v0, const NurbsCurve &curve_v1)
 由四条边界曲线创建 Coons 曲面 更多...
 
NurbsSurface vde::curves::extrude_curve (const NurbsCurve &curve, const Vector3D &direction, double length)
 沿方向向量拉伸 NURBS 曲线为曲面 更多...
 
NurbsCurve vde::curves::extract_boundary_curve (const NurbsSurface &surf, int edge)
 提取 NURBS 曲面的等参边界曲线 更多...
 
std::pair< std::vector< Point3D >, std::vector< std::array< int, 3 > > > vde::curves::tessellate (const std::function< Point3D(double, double)> &eval, int res_u, int res_v)
 均匀参数化曲面三角化 更多...
 
std::pair< std::vector< Point3D >, std::vector< std::array< int, 3 > > > vde::curves::adaptive_tessellate (const std::function< Point3D(double, double)> &eval, const std::function< Vector3D(double, double)> &normal_fn, int min_res=2, int max_depth=6, double angle_threshold_deg=5.0)
 自适应曲面三角化 更多...
 

详细描述

Bézier、B-Spline、NURBS 曲线与曲面的求值、求导、细分

函数说明

◆ adaptive_tessellate()

std::pair<std::vector<Point3D>, std::vector<std::array<int, 3> > > vde::curves::adaptive_tessellate ( const std::function< Point3D(double, double)> &  eval,
const std::function< Vector3D(double, double)> &  normal_fn,
int  min_res = 2,
int  max_depth = 6,
double  angle_threshold_deg = 5.0 
)

自适应曲面三角化

基于法向角度偏差的自适应细分策略: 从 min_res×min_res 初始网格开始,对每个四边形检查四个角点的法向偏差。 若任意相邻角点间的法向夹角超过 angle_threshold_deg,则将该四边形四分细分。

相比均匀 tessellate() 的优点:

  • 曲率大的区域自动增加采样密度
  • 平坦区域保持粗糙网格,节省面数
参数
eval曲面求值函数 eval(u,v) -> Point3D
normal_fn单位法向函数 normal_fn(u,v) -> Vector3D
min_res初始每向子分段数(≥ 1),默认 2
max_depth最大递归深度,限制总面数,默认 6
angle_threshold_deg法向角度偏差阈值(度),默认 5.0
返回
{顶点数组, 三角形索引数组}
注解
最终面数上限约为 2·min_res²·4^max_depth(实际远小于此上限)
auto [verts, tris] = adaptive_tessellate(
[&](double u, double v) { return surf.evaluate(u,v); },
[&](double u, double v) { return surf.normal(u,v); },
2, 5, 3.0); // 3° 偏差阈值,最大深度 5
std::pair< std::vector< Point3D >, std::vector< std::array< int, 3 > > > adaptive_tessellate(const std::function< Point3D(double, double)> &eval, const std::function< Vector3D(double, double)> &normal_fn, int min_res=2, int max_depth=6, double angle_threshold_deg=5.0)
自适应曲面三角化
参见
tessellate

◆ blend_surfaces()

NurbsSurface vde::curves::blend_surfaces ( const NurbsSurface surf_a,
const NurbsSurface surf_b,
int  edge_a,
int  edge_b,
double  blend_radius 
)

两 NURBS 曲面沿边界边的过渡面

提取两个曲面的指定边界曲线,各沿法向向内偏移 blend_radius 后, 在两偏移曲线之间创建直纹面作为过渡。

参数
surf_a第一个曲面
surf_b第二个曲面
edge_asurf_a 的边界边索引(0=u_min, 1=u_max, 2=v_min, 3=v_max)
edge_bsurf_b 的边界边索引(0=u_min, 1=u_max, 2=v_min, 3=v_max)
blend_radius过渡半径
返回
过渡 NURBS 曲面(在偏移边界曲线间的直纹面)
注解
过渡面与原始曲面在边界处为 C⁰ 连续(非切线连续)
// surf_a 的 u_max 边过渡到 surf_b 的 u_min 边
auto blend = blend_surfaces(surf_a, surf_b,
1, 0, // edge indices: umax → umin
0.5); // blend radius
NurbsSurface blend_surfaces(const NurbsSurface &surf_a, const NurbsSurface &surf_b, int edge_a, int edge_b, double blend_radius)
两 NURBS 曲面沿边界边的过渡面
参见
ruled_surface

◆ coons_patch()

NurbsSurface vde::curves::coons_patch ( const NurbsCurve curve_u0,
const NurbsCurve curve_u1,
const NurbsCurve curve_v0,
const NurbsCurve curve_v1 
)

由四条边界曲线创建 Coons 曲面

双线性混合: S(u,v) = (1-u)·C_{v0}(v) + u·C_{v1}(v)

  • (1-v)·C_{u0}(u) + v·C_{u1}(u)
  • 角点修正项

四条曲线须围成闭合环且有兼容的阶次/节点结构。

参数
curve_u0v=0 处边界(沿 u 方向)
curve_u1v=1 处边界(沿 u 方向)
curve_v0u=0 处边界(沿 v 方向)
curve_v1u=1 处边界(沿 v 方向)
返回
Coons 曲面
注解
仅保证边界插值,不保证内部形状与设计意图一致
auto patch = coons_patch(bottom, top, left, right);
NurbsSurface coons_patch(const NurbsCurve &curve_u0, const NurbsCurve &curve_u1, const NurbsCurve &curve_v0, const NurbsCurve &curve_v1)
由四条边界曲线创建 Coons 曲面
参见
ruled_surface

◆ extract_boundary_curve()

NurbsCurve vde::curves::extract_boundary_curve ( const NurbsSurface surf,
int  edge 
)

提取 NURBS 曲面的等参边界曲线

沿曲面的 u/v 参数极值提取边界 NURBS 曲线。

参数
surf输入曲面
edge边界索引:0=u_min, 1=u_max, 2=v_min, 3=v_max
返回
指定边界上的 NURBS 曲线
注解
边界曲线继承原曲面该方向的阶次和节点向量
auto umin_curve = extract_boundary_curve(surf, 0);
auto vmax_curve = extract_boundary_curve(surf, 3);
NurbsCurve extract_boundary_curve(const NurbsSurface &surf, int edge)
提取 NURBS 曲面的等参边界曲线

◆ extrude_curve()

NurbsSurface vde::curves::extrude_curve ( const NurbsCurve curve,
const Vector3D &  direction,
double  length 
)

沿方向向量拉伸 NURBS 曲线为曲面

创建阶次 (d)×1 的 NURBS 曲面(d = 曲线阶次)。 第一排控制点 = 曲线控制点,最后一排 = 偏移后的控制点。

参数
curve截面曲线
direction拉伸方向(内部归一化)
length拉伸长度
返回
拉伸 NURBS 曲面
auto surface = extrude_curve(profile, {0, 0, 1}, 10.0);
// 沿 Z 轴拉伸 10 单位
NurbsSurface extrude_curve(const NurbsCurve &curve, const Vector3D &direction, double length)
沿方向向量拉伸 NURBS 曲线为曲面

◆ offset_surface()

NurbsSurface vde::curves::offset_surface ( const NurbsSurface surf,
double  distance 
)

NURBS 曲面等距偏移

基于 Piegl & Tiller 近似方法:在每个控制点的 Greville 横坐标处 计算曲面法向,将控制点沿法向平移 distance。

参数
surf输入 NURBS 曲面
distance偏移距离(正值 = 沿法向外,负值 = 向内)
返回
偏移后的 NURBS 曲面(近似,阶次与原曲面相同)
注解
这是几何近似,非精确偏移。对于大变曲率曲面,增大控制点数量 可提高精度。精确偏移需要更高阶曲面或细分方法。
偏移可能导致自交(distance 超过曲面局部曲率半径时)
参见
trim_surface blend_surfaces

◆ ruled_surface()

NurbsSurface vde::curves::ruled_surface ( const NurbsCurve curve_a,
const NurbsCurve curve_b 
)

两 NURBS 曲线间的直纹面

在两条曲线之间线性插值生成曲面: S(u,v) = (1-v)·C_a(u) + v·C_b(u) 纵向保持输入曲线的阶次,直纹方向为线性(degree=1)。

参数
curve_a第一条曲线(v=0 边界)
curve_b第二条曲线(v=1 边界)
返回
直纹 NURBS 曲面
注解
两条曲线需有兼容的阶次和节点结构(内部执行升阶和节点精化)
auto ruled = ruled_surface(profile_bottom, profile_top);
NurbsSurface ruled_surface(const NurbsCurve &curve_a, const NurbsCurve &curve_b)
两 NURBS 曲线间的直纹面
参见
coons_patch blend_surfaces

◆ tessellate()

std::pair<std::vector<Point3D>, std::vector<std::array<int, 3> > > vde::curves::tessellate ( const std::function< Point3D(double, double)> &  eval,
int  res_u,
int  res_v 
)

均匀参数化曲面三角化

在参数域 [0,1]×[0,1] 上生成 res_u×res_v 均匀采样点, 调用 eval(u,v) 求值后将每个四边形拆为两个三角形。

参数
eval曲面求值函数 eval(u,v) -> Point3D,参数 (u,v) ∈ [0,1]×[0,1]
res_uu 方向子分段数(≥ 1)
res_vv 方向子分段数(≥ 1)
返回
{顶点数组, 三角形索引数组},三角形为 {i0,i1,i2}
注解
总顶点数 = (res_u+1)×(res_v+1),三角形数 = 2×res_u×res_v
auto [verts, tris] = tessellate(
[&](double u, double v) { return surface.evaluate(u,v); },
20, 20);
std::pair< std::vector< Point3D >, std::vector< std::array< int, 3 > > > tessellate(const std::function< Point3D(double, double)> &eval, int res_u, int res_v)
均匀参数化曲面三角化
参见
adaptive_tessellate

◆ trim_surface()

NurbsSurface vde::curves::trim_surface ( const NurbsSurface surf,
double  u_min,
double  u_max,
double  v_min,
double  v_max 
)

NURBS 曲面参数域裁剪

将原始定义域 [u_min,u_max]×[v_min,v_max] 通过节点重参数化 映射到 [0,1]×[0,1],不改变控制点和权重——仅缩放平移节点向量, 曲面几何保持不变。

参数
surf输入曲面
u_min,u_max裁剪后的 u 参数范围(必须在原 domain 内)
v_min,v_max裁剪后的 v 参数范围(必须在原 domain 内)
返回
裁剪后的 NURBS 曲面
注解
裁剪是"软裁剪"——几何不变,仅改变参数化。如需"硬裁剪" (沿等参线切除曲面边缘),需结合曲面细分。
auto trimmed = trim_surface(surf, 0.2, 0.8, 0.1, 0.9);
// trimmed 的参数域为 [0,1]×[0,1],但几何仅对应原曲面的子区域
NurbsSurface trim_surface(const NurbsSurface &surf, double u_min, double u_max, double v_min, double v_max)
NURBS 曲面参数域裁剪