www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtradeoffgui/@mmSiteGraphView/pFindModelSite.m
function idx = pFindModelSite(obj) %PFINDMODELSITE Find the model site index of the last hit point % % PFINDMODELSITE(OBJ) returns the index of the model site that is closest % to the last hit point in the axes. % Copyright 2000-2005 The MathWorks, Inc. and Ford Global Technologies, Inc. axisorder = obj.MessageService.AxisOrder; pt = obj.LastHitPoint; pt = pt([axisorder(2) axisorder(1)]); pts = obj.MessageService.ModelSites; if isempty(pts) idx = []; else % Perform nearest-point match in noramlized coordinates dx = (pts(:,1)-pt(1))./(max(pts(:,1))-min(pts(:,1))); dy = (pts(:,2)-pt(2))./(max(pts(:,2))-min(pts(:,2))); d = dx.^2 + dy.^2; [unused, idx] = min(d); end