点到三维网格最近边的距离

xiaoxiao2021-02-28  96

之间写过点到三维网格最近顶点的距离,也写过点到三维网格上面点的最近距离,今天po一篇点到三维网格最近边的距离。

其实在刚刚我提到的我的后面这篇博文里,已经有相关介绍了。在这里要感谢 Daniel Frisch在mathworks上的贡献point2trimesh( ) — Distance Between Point and Triangulated Surface,我这一系列博文的代码都是根据他的代码改写的。

首先计算到点的距离的最小值,再计算到边距离的最小值,二者再取小者。(如果最短距离是到点的,其实也就意味着到最近边的距离是到其顶点的距离)

下面是我的代码

function [ distances, surface_points,F,Edges] = point2mesh_line( faces,vertices,qPoints ) assert(~isempty(faces) && ~isempty(vertices), 'Invalid argument: ''Faces'' and ''Vertices'' mustn''t be empty.') assert(max(faces(:))<=size(vertices,1), 'The value of ''Faces'' is invalid: the maximum vertex ID is bigger than the number of vertices in ''Vertices''') % Calculate normals r1 = vertices(faces(:,1),:); % (#faces x 3) % 1st vertex of every face r2 = vertices(faces(:,2),:); % (#faces x 3) % 2nd vertex of every face r3 = vertices(faces(:,3),:); % (#faces x 3) % 3rd vertex of every face normals = cross((r2-r1),(r3-r1),2); % (#faces x 3) normal vector of every face normals = bsxfun(@rdivide,normals,sqrt(sum(normals.^2,2))); % (#faces x 3) normalized normal vector of every face if isempty(qPoints) distances = []; surface_points = []; return end %% Distance Calculation nQPoints = size(qPoints,1); D = NaN(nQPoints,1); P = NaN(nQPoints,3); Edges=NaN(nQPoints,2); F = NaN(nQPoints,2);
转载请注明原文地址: https://www.6miu.com/read-42696.html

最新回复(0)