Files
ViewDesignEngine/include/vde/brep/measure.h
T

106 lines
2.8 KiB
C++
Raw Normal View History

#pragma once
/**
* @file measure.h
* @brief B-Rep 测量工具
*
* 提供 B-Rep 实体的几何属性测量函数:
* - 体积(散度定理)
* - 表面积(三角剖分求和)
* - 质心
* - 两实体间最小距离
*
* @ingroup brep
*/
#include "vde/brep/brep.h"
#include "vde/brep/assembly.h"
#include "vde/core/point.h"
#include <Eigen/Dense>
namespace vde::brep {
/**
* @brief 质量属性结果
*
* 包含体积、质心、惯性张量和回转半径。
* 所有量基于单位密度 ρ=1。
*/
struct MassProperties {
double volume = 0.0; ///< 体积
core::Point3D centroid{0, 0, 0}; ///< 质心
Eigen::Matrix3d inertia{Eigen::Matrix3d::Zero()}; ///< 惯性张量 (绕质心)
core::Vector3D gyration_radii{0, 0, 0}; ///< 回转半径 sqrt(I/m) 各轴
};
/**
* @brief 计算两个 B-Rep 实体间的最小距离
*
* 通过将两个实体 tessellate 为三角网格,
* 计算所有三角形对之间的最小距离。
*
* @param a 第一个 B-Rep 实体
* @param b 第二个 B-Rep 实体
* @return 最小距离(≥ 0)。若两实体相交则返回 0。
*/
[[nodiscard]] double distance(const BrepModel& a, const BrepModel& b);
/**
* @brief 计算 B-Rep 实体的表面积
*
* 将所有面 tessellate 为三角形,求和三角形面积。
*
* @param body B-Rep 实体
* @return 表面积(平方单位)
*/
[[nodiscard]] double surface_area(const BrepModel& body);
/**
* @brief 计算封闭 B-Rep 实体的体积
*
* 使用散度定理(divergence theorem):
*
* V = (1/3) Σ (面心 · 面法向量 * 三角形面积)
*
* 对 tessellated 网格的所有三角形求和。
*
* @param body 封闭 B-Rep 实体
* @return 体积(立方单位)
*
* @pre body 应为封闭实体(水密)
*/
[[nodiscard]] double volume(const BrepModel& body);
/**
* @brief 计算 B-Rep 实体的质心
*
* 使用 tessellated 网格计算面积加权质心。
*
* @param body B-Rep 实体
* @return 质心坐标
*/
[[nodiscard]] core::Point3D centroid(const BrepModel& body);
/**
* @brief 单实体完整质量属性
*
* 绕质心的惯性张量(密度 ρ=1)。使用四面体分解。
*/
[[nodiscard]] MassProperties mass_properties(const BrepModel& body);
/**
* @brief 装配体递归质量属性
*
* 遍历装配树,考虑每个零件的局部变换,合并所有质量属性。
*/
[[nodiscard]] MassProperties assembly_mass_properties(const AssemblyNode& node,
const core::Transform3D& parent_tf = core::Transform3D::Identity());
/**
* @brief 两实体间的最小间隙
*
* 比 distance() 更高效:先用 AABB 过滤,仅在接近时检测。
* @return 最小间隙。若相交则返回 0。
*/
[[nodiscard]] double clearance(const BrepModel& a, const BrepModel& b);
} // namespace vde::brep