问题
I am building a GUI that plot a 3D figure by pressing button. I am trying to return a distance value between 2 points when I select the 2 points using datacursormode on the figure. I know the formula to calculate the distance, but I don't know how to make the data cursor return the (X,Y,Z) value of the 2 points selected.
Thanks.
回答1:
%// retrieve the data cursor manager for the figure
dcm = datacursormode(gcf) ;
%// get all the datatips information in a structure
dtip_info = dcm.getCursorInfo ;
%// extract the coordinates of each data tip from the structure
Coordinates_Datatip1 = dtip_info(1).Position ;
Coordinates_Datatip2 = dtip_info(2).Position ;
This assume you already have 2 datatips in the current figure. Each "Coordinates_Datatip" variable will contain 3 scalar values x,y and z position of your datatips.
来源:https://stackoverflow.com/questions/22691417/computing-distance-between-between-2-point-of-a-3d-figure-using-datacursor