Get 3d Coordinate Of Mouse In Axis

别来无恙 提交于 2020-02-07 12:29:32

问题


I used below code from link to plot mouse position in axes(when mouse moving in axes) :

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)

but plotted position differs from mouse location.


回答1:


Finally Found Another Solution : 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);


来源:https://stackoverflow.com/questions/26863027/get-3d-coordinate-of-mouse-in-axis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!