-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathArrowGraphic.m
61 lines (54 loc) · 1.78 KB
/
ArrowGraphic.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
classdef ArrowGraphic
%UNTITLED28 Summary of this class goes here
% Detailed explanation goes here
properties
handle
base
vec
end
methods
function obj = ArrowGraphic(parent,radius,headRadius, headLen, color,alpha)
if nargin < 6
alpha = 1;
end
obj.handle = hgtransform('Parent',parent);
g = hggroup('Parent',obj.handle);
cylinder(g, [0 0 0; 0 0 1-headLen], radius, color,alpha);
cone(g,[0 0 1-headLen; 0 0 1], headRadius, color,alpha);
end
function obj = setArrow(obj, base, vec)
obj.base = base;
obj.vec = vec;
obj.updateGraphics();
end
function obj = setVec(obj, vec)
obj.base = [0 0 0];
obj.vec = vec;
obj.updateGraphics();
end
function obj = updateGraphics(obj)
base = obj.base;
vec = obj.vec;
nv = norm(vec);
if nv < 1e-6
set(obj.handle,'Visible','off');
else
vecn = vec / nv;
v = [0 0 1];
ax = cross(v,vecn);
if norm(ax) < 1e-6
ax = [0 0 1];
ang = 0;
else
if dot(v,vecn) <-.9999
ang = pi;
else
ang = acos(dot(v,vecn));
end
end
M = makehgtform('translate',base,'axisrotate',ax,ang,'scale',[1 1 nv]);
set(obj.handle,'Matrix',M,'Visible','on');
end
end
end
end