我使用link下面的代码在轴上绘制鼠标位置(当鼠标在轴上移动时):
point = get(gca, 'CurrentPoint'); % mouse click position
camPos = get(gca, 'CameraPosition'); % camera position
camTgt = get(gca, 'CameraTarget'); % where the camera is pointing to
camDir = camPos - camTgt; % camera direction
camUpVect = get(gca, 'CameraUpVector'); % camera 'up' vector
zAxis = camDir/norm(camDir);
upAxis = camUpVect/norm(camUpVect);
xAxis = cross(upAxis, zAxis);
yAxis = cross(zAxis, xAxis);
rot = [xAxis; yAxis; zAxis]; % view rotation
rotatedPointFront = rot * point' ;
plot3(rotatedPointFront(1),rotatedPointFront(2),rotatedPointFront(3), 'r.','MarkerSize', 20)
但绘制的位置与鼠标位置不同。
答案 0 :(得分:0)
终于找到了另一个解决方案: http://www.mathworks.com/matlabcentral/fileexchange/1600-dispcoord1-2-m
hold on;
pos=get(gca,'CurrentPoint');
POS=mean(pos);
POS=round(POS*1000)/1000;
disp(POS);
plot3(POS(1),POS(2),POS(3),'r.', 'MarkerSize', 10);