Home > bioelectromagnetism > mesh_vertex_nearest.m

mesh_vertex_nearest - find nearest vertices to specified points Usage: [nearestIndex,nearestValues] = mesh_vertex_nearest(vertices,points) vertices is a Vx3 matrix of 3D Cartesian coordinates. points is a Px3 matrix of 3D Cartesian coordinates. These points need not be among the vertices, but they are somewhere near to particular points in the vertices cloud. The function finds just one of the nearest vertices in the cloud for each of these points. nearestIndex is the indices into vertices nearest to points nearestValues is the coordinates for nearestIndex This function is just a wrapper for dsearchn.

0001 function [nearestIndex,nearestValues] = mesh_vertex_nearest(vertices,points) 0002 0003 % mesh_vertex_nearest - find nearest vertices to specified points 0004 % 0005 % Usage: [nearestIndex,nearestValues] = mesh_vertex_nearest(vertices,points) 0006 % 0007 % vertices is a Vx3 matrix of 3D Cartesian coordinates. 0008 % points is a Px3 matrix of 3D Cartesian coordinates. These points need not 0009 % be among the vertices, but they are somewhere near to particular points 0010 % in the vertices cloud. The function finds just one of the nearest 0011 % vertices in the cloud for each of these points. 0012 % 0013 % nearestIndex is the indices into vertices nearest to points 0014 % nearestValues is the coordinates for nearestIndex 0015 % 0016 % This function is just a wrapper for dsearchn. 0017 % 0018 0019 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:35 $ 0020 0021 % Author: Darren.Weber_at_radiology.ucsf.edu 0022 % Created: 23 May 2004 0023 % 0024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0025 0026 fprintf('...Finding nearest vertices to points.\n'); 0027 0028 0029 nearestIndex = dsearchn(vertices,points); 0030 nearestValues = vertices(nearestIndex,:); 0031 0032 % for p = 1:length(points), 0033 % tmp = repmat(points(p,:),length(vertices),1); 0034 % [minValue, nearestIndex] = min(abs(vertices - tmp)); 0035 % end 0036 % nearVertex = vertices(nearestIndex,:); 0037 0038 0039 0040 0041 0042 return

Generated on Mon 15-Aug-2005 15:36:19 by