function Drag()
%实现鼠标拖拽功能
DragMode();
end
function DragMode()
global f aH hl
aH
f
a = 10
set(aH,'ButtonDownFcn',@startDragFcn);
set(f,'WindowButtonUpFcn',@stopDragFcn);
a = 15
function startDragFcn(varargin)
%拖拽实现函数
a = 30
set(f,'WindowButtonMotionFcn',@draggingFcn)
end
function draggingFcn(varargin)
%得到鼠标当前点坐标,计算当前点与起始点坐标之差,修改起始坐标点为二次起始点
global bd o1 o2
global i1 i2 i3
global delta
global ii4 oo6 oo7
a = 40
if bd == 1
pos = get(aH,'CurrentPoint');
%计算鼠标角度
if pos(1,1)-((o1+o2)/2)>=0
alpha = atan(pos(1,2)/((pos(1,1)-((o1+o2)/2))));
elseif pos(1,2)>=0
alpha = atan(pos(1,2)/((pos(1,1)-((o1+o2)/2))))+pi;
else
alpha = atan(pos(1,2)/((pos(1,1)-((o1+o2)/2))))-pi;
end
alpha
%计算初始角度
if i1-((o1+o2)/2)>=0
startalpha = atan(i3/(i1-((o1+o2)/2)));
elseif i3>=0
startalpha = atan(i3/(i1-((o1+o2)/2)))+pi;
else
startalpha = atan(i3/(i1-((o1+o2)/2)))-pi;
end
%计算角度差
delta = alpha - startalpha;
delta = delta/2;
end
ii4 = delta;
oo6 = 0.5*(i1+i2)+0.5*(i1-i2)*cos(2*ii4)-i3*sin(2*ii4);
oo7 = 0.5*(i1-i2)*sin(2*ii4)+i3*cos(2*ii4);
%设置直线属性
set(hl,'XData',[(o1+o2)/2,oo6]);
set(hl,'YData',[0,oo7]);
% string = strcat(num2str(oo6),',',num2str(007));
% text(oo6,oo7,string);
end
function stopDragFcn(varargin)
set(f,'WindowButtonMotionFcn','');
end
end