✅作者简介:热爱科研的Matlab仿真开发者,擅长毕业设计辅导、数学建模、数据处理、程序设计科研仿真。
🍎完整代码获取 定制创新 论文复现点击:Matlab科研工作室
👇 关注我领取海量matlab电子书和数学建模资料
🍊个人信条:做科研,博学之、审问之、慎思之、明辨之、笃行之,是为:博学慎思,明辨笃行。
🔥 内容介绍
主要围绕无人机桥梁检查覆盖路径规划展开,涉及模型数据读取、网格划分、路径生成、偏移处理、碰撞检测、路径重规划、采样以及相关参数计算与输出等功能。以下为详细解读:
1. 模型选择与数据读取
- 模型选择
:通过
model变量选择不同模型,如'dice'、'portal'、'pillar'等,不同模型对应不同的数据文件。 - 数据文件读取
:根据所选模型,打开相应的映射文件(如
'3D 2D maping.txt')、面文件(如'faces.txt')和表面法向量文件(如'surface_normal.txt'),并使用textscan函数读取文件内容。同时加载特定的轨迹数据(如test_traj_simple.mat)。
2. 数据预处理
- 数据清理
:对读取的数据进行清理,去除字符串中的特定字符(如
'('、')'、','等)。 - 数据转换
:将清理后的字符串数据转换为数值型数据,如顶点 ID、坐标、UV 坐标、面 ID 以及表面法向量等。
- 数据缩放
:对于特定模型(如
'pillar'),对顶点坐标进行缩放处理。
3. 三角剖分与可视化
- 三角剖分
:根据面信息和顶点信息,创建 UV 映射和 3D 模型的三角剖分对象。
- 可视化
:在图形窗口中绘制 UV 映射的三角图和 3D 模型的表面图,展示模型的几何形状。
4. 网格划分
- 3D 网格划分
:根据模型的边界和设定的网格大小,计算 3D 网格的数量和边界信息。
- 2D 网格划分
:对 UV 空间进行网格划分,计算网格数量和相关参数。
5. 计算三角形质心
- UV 质心计算
:计算每个三角形网格在 UV 空间的质心,并将质心分配到对应的 2D 网格中。
- 3D 质心计算
:计算每个三角形网格在 3D 空间的质心,并将质心分配到对应的 3D 网格中。
- 比例计算
:计算 UV 到 3D 的比例关系。
6. 轨迹转换与可见性分析
- 轨迹转换
:将 2D 轨迹点转换为 3D 空间中的点,并确定每个轨迹点对应的三角形面 ID。
- 可见性分析
:根据 UV 到 3D 的比例和视野半径,确定每个轨迹点在 UV 空间中可见的三角形面,并在图中可视化展示。
7. 路径偏移
- 路径分段
:根据轨迹点对应的面 ID,将轨迹划分为不同的线段。
- 偏移计算
:对每个线段进行 3D 偏移计算,得到偏移后的路径。
8. 碰撞检测与路径重规划
- 碰撞检测
:检查偏移后的路径是否与模型发生碰撞,并标记碰撞点和地面 clearance 信息。
- 路径重规划
:根据碰撞检测结果,对路径进行重规划,生成避开碰撞的新路径。
9. 路径下采样
- 下采样目标设定
:设定下采样的目标距离,以减少路径点的数量。
- 下采样过程
:根据点与点之间的距离,对路径进行下采样,直到满足下采样目标。
10. 计算与输出
- 距离计算
:计算下采样后路径点到模型表面的距离,并统计平均、中位、最大、最小距离以及标准差。
- 分布绘制
:绘制距离的直方图和拟合曲线,展示距离的分布情况。
- 可见性计算
:计算 3D 空间中的可见性,并可视化展示覆盖的表面。
- 覆盖率计算
:计算路径的覆盖率。
- 数据输出
:将最终的路径和相机指令输出到文本文件中。
⛳️ 运行结果
📣 部分代码
function interpPoints = Hermite_plot(points)
% Number of points
n = size(points, 1);
% Calculate tangent vectors using finite differencing
tangents = zeros(n, 3);
% Calculate tangent vectors for interior points
for i = 2:n-1
tangents(i, :) = (points(i+1, :) - points(i-1, :)) / norm(points(i+1, :) - points(i-1, :));
end
% Estimate tangent vectors for the first and last points
tangents(1, :) = (points(2, :) - points(1, :)) / norm(points(2, :) - points(1, :));
tangents(n, :) = (points(n, :) - points(n-1, :)) / norm(points(n, :) - points(n-1, :));
% Create parameter t ranging from 0 to 1
t = linspace(0, 1, n);
% Initialize arrays to store interpolated points
interpPoints = zeros(5000, 3); % Increase 100 if you want more interpolated points
% Generate Hermite spline for each segment
for i = 1:n-1
% Create a parameter t within the range of the segment
ti = linspace(t(i), t(i+1), 100); % Increase 100 for more interpolated points
% Calculate Hermite blending functions
h00 = 2*ti.^3 - 3*ti.^2 + 1;
h01 = ti.^3 - 2*ti.^2 + ti;
h10 = -2*ti.^3 + 3*ti.^2;
h11 = ti.^3 - ti.^2;
% Calculate interpolated points using Hermite spline formula
interpPoints((i-1)*100+1:i*100, :) = h00' * points(i, :) + h01' * tangents(i, :) + h10' * points(i+1, :) + h11' * tangents(i+1, :);
end
% Plot the original points and the interpolated points
hold on;
plot3(points(:, 1), points(:, 2), points(:, 3), '.','Color',[0.8500 0.3250 0.0980],'MarkerSize',15); % Original points
plot3(interpPoints(:, 1), interpPoints(:, 2), interpPoints(:, 3), 'color',[0 0.4470 0.7410],'LineWidth',2); % Interpolated points
hold off;
grid on;
xlabel('X (m)');
ylabel('Y (m)');
zlabel('Z (m)');
% legend('Original Points', 'Interpolated Points');
end