博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
intersectLineMesh3d
阅读量:4041 次
发布时间:2019-05-24

本文共 2582 字,大约阅读时间需要 8 分钟。

C:\TestMatlab\geom3d
function [points, pos, faceInds] = intersectLineMesh3d(line, vertices, faces, varargin)%INTERSECTLINEMESH3D Intersection points of a 3D line with a mesh%%   INTERS = intersectLineMesh3d(LINE, VERTICES, FACES)%   Compute the intersection points between a 3D line and a 3D mesh defined%   by vertices and faces.%%   [INTERS POS INDS] = intersectLineMesh3d(LINE, VERTICES, FACES)%   Also returns the position of each intersection point on the input line,%   and the index of the intersected faces.%   If POS > 0, the point is also on the ray corresponding to the line. %   %   Example%   intersectLineMesh3d%%   See also%   meshes3d, triangulateFaces, intersectLineTriangle3d%% ------% Author: David Legland% e-mail: david.legland@grignon.inra.fr% Created: 2011-12-20,    using Matlab 7.9.0.529 (R2009b)% Copyright 2011 INRA - Cepia Software Platform.tol = 1e-12;if ~isempty(varargin)    tol = varargin{1};end% ensure the mesh has triangular facestri2Face = [];if iscell(faces) || size(faces, 2) ~= 3    [faces, tri2Face] = triangulateFaces(faces);end% find triangle edge vectorst0  = vertices(faces(:,1), :);u   = vertices(faces(:,2), :) - t0;v   = vertices(faces(:,3), :) - t0;% triangle normaln   = normalizeVector3d(vectorCross3d(u, v));% direction vector of linedir = line(4:6);% vector between triangle origin and line originw0 = bsxfun(@minus, line(1:3), t0);a = -dot(n, w0, 2);b = dot(n, repmat(dir, size(n, 1), 1), 2);valid = abs(b) > tol & vectorNorm3d(n) > tol;% compute intersection point of line with supporting plane% If pos < 0: point before ray% IF pos > |dir|: point after edgepos = a ./ b;% coordinates of intersection pointpoints = bsxfun(@plus, line(1:3), bsxfun(@times, pos, dir));%% test if intersection point is inside triangle% normalize direction vectors of triangle edgesuu  = dot(u, u, 2);uv  = dot(u, v, 2);vv  = dot(v, v, 2);% coordinates of vector v in triangle basisw   = points - t0;wu  = dot(w, u, 2);wv  = dot(w, v, 2);% normalization constantD = uv.^2 - uu .* vv;% test first coordinates = (uv .* wv - vv .* wu) ./ D;% ind1 = s < 0.0 | s > 1.0;ind1 = s < -tol | s > (1.0 + tol);points(ind1, :) = NaN;pos(ind1) = NaN;% test second coordinate, and third triangle edget = (uv .* wu - uu .* wv) ./ D;% ind2 = t < 0.0 | (s + t) > 1.0;ind2 = t < -tol | (s + t) > (1.0 + tol);points(ind2, :) = NaN;pos(ind2) = NaN;% keep only interesting pointsinds = ~ind1 & ~ind2 & valid;points = points(inds, :);pos = pos(inds);faceInds = find(inds);% convert to face indices of original meshif ~isempty(tri2Face)    faceInds = tri2Face(faceInds);end

转载地址:http://dvxdi.baihongyu.com/

你可能感兴趣的文章
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>
[LeetCode By MYSQL] Combine Two Tables
查看>>
Android下调用收发短信邮件等(转载)
查看>>
Android中电池信息(Battery information)的取得
查看>>
SVN客户端命令详解
查看>>
Android/Linux 内存监视
查看>>
Linux系统信息查看
查看>>
用find命令查找最近修改过的文件
查看>>
Android2.1消息应用(Messaging)源码学习笔记
查看>>
Android之TelephonyManager类的方法详解
查看>>
android raw读取超过1M文件的方法
查看>>
ubuntu下SVN服务器安装配置
查看>>
MPMoviePlayerViewController和MPMoviePlayerController的使用
查看>>
CocoaPods实践之制作篇
查看>>
[Mac]Mac 操作系统 常见技巧
查看>>
苹果Swift编程语言入门教程【中文版】
查看>>
捕鱼忍者(ninja fishing)之游戏指南+游戏攻略+游戏体验
查看>>