Files
ViewDesignEngine/include/vde/curves/surface_intersection.h
T
茂之钳 314543f7a5
CI / Build & Test (push) Failing after 35s
CI / Release Build (push) Failing after 16m58s
Build & Test / build-and-test (push) Has been cancelled
Build & Test / python-bindings (push) Has been cancelled
tmp: comment out plane intersect to test build
2026-07-24 13:13:55 +00:00

83 lines
2.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include "vde/curves/nurbs_surface.h"
#include "vde/curves/nurbs_curve.h"
#include "vde/core/aabb.h"
#include <vector>
#include <functional>
#include <utility>
namespace vde::curves {
/**
* @brief 曲面-曲面求交结果
*
* 包含交线上离散采样点的 3D 坐标及其在两曲面上的参数坐标,
* 以及可选的拟合 NURBS 曲线。
*
* @ingroup curves
*/
struct IntersectionCurve {
/// 交线采样点(3D 空间坐标)
std::vector<core::Point3D> points;
/// 各采样点在曲面 A 上的参数坐标 (u1, v1)
std::vector<std::pair<double, double>> params_a;
/// 各采样点在曲面 B 上的参数坐标 (u2, v2)
std::vector<std::pair<double, double>> params_b;
/// 沿交线采样点拟合的 NURBS 曲线(可选)
};
/**
* @brief 两 NURBS 曲面求交
*
* 算法:递归子分 AABB 剔除 → 叶节点种子搜索 → Newton 精化 + 交线追踪 →
* 弦长参数化 NURBS 拟合。
*
* @param surf_a 曲面 A
* @param surf_b 曲面 B
* @param max_depth 最大递归深度(默认 5)
* @param tolerance 3D 空间收敛容差(默认 1e-4)
* @return 交线列表(无交则空)
*
* @note 本实现为工业级近似算法,适用于一般 CAD 场景。
* 对奇异情况(切线接触、边界交线等)可能丢线。
* @code{.cpp}
* auto curves = intersect_surfaces(cyl, sphere, 6, 1e-5);
* for (auto& c : curves) {
* for (auto& p : c.points) { /* 使用交线上的点 */ }
* }
* @endcode
* @ingroup curves
*/
[[nodiscard]] std::vector<IntersectionCurve> intersect_surfaces(
const NurbsSurface& surf_a,
const NurbsSurface& surf_b,
int max_depth = 5,
double tolerance = 1e-4);
/**
* @brief 平面与 NURBS 曲面求交
*
* 使用等值线追踪法:在曲面参数域上采样 signed_distance
* 追踪零等值线得到交线。
*
* @param surf NURBS 曲面
* @param point 截平面上一点
* @param normal 截平面法向(自动归一化)
* @param grid_res 参数域网格分辨率(默认 32)
* @return 交线列表(通常为一条)
*
* @code{.cpp}
* // 用 Z=0 平面截圆柱
* auto curves = intersect_plane_surface(cylinder, {0,0,0}, {0,0,1});
* @endcode
* @ingroup curves
*/
[[nodiscard]] std::vector<IntersectionCurve> intersect_plane_surface(
// const NurbsSurface& surf,
// const core::Point3D& point,
// const core::Vector3D& normal,
// int grid_res = 32);
//
} // namespace vde::curves