Skip to content

Commit 5aaf665

Browse files
committed
updateQuiver plots arrowheads on the ends of arrows :)
1 parent 30597f4 commit 5aaf665

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

plotly/plotlyfig_aux/handlegraphics/updateQuiver.m

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@
6464
udata = reshape(quiver_data.UData,1,size(quiver_data.UData,1)*size(quiver_data.UData,1));
6565
vdata = reshape(quiver_data.VData,1,size(quiver_data.VData,1)*size(quiver_data.VData,1));
6666

67-
%------------------------------------------------------------------------%
68-
% JNJ: Need to implement the arrowheads!!! Bit of an oversight...!
69-
% Also, compare Python plotly arrowheads to the matlab arrowheads...
70-
% At the same time, we might make sure the line length adjusts
71-
% appropriately.
72-
% Might as well make arrowheads scaleable, too.
7367
%------------------------------------------------------------------------%
7468

7569
%-quiver x-%
@@ -94,6 +88,46 @@
9488

9589
%-------------------------------------------------------------------------%
9690

91+
%-quiver barbs-%
92+
max_head_size = 0.15; % 'MaxHeadSize' scalar, matlab clips to 0.2
93+
head_width = deg2rad(15); % barb width, not supported by matlab
94+
for n = 1:length(xdata) % xdata and ydata had better be the same length... throw an exception if this isn't true?
95+
% length of arrow
96+
l = norm([0.1*udata(n), 0.1*vdata(n)]);
97+
98+
% angle of arrow
99+
phi = atan2(vdata(n),udata(n));
100+
101+
% make barb with specified angular width and length prop. to arrow
102+
barb = [...
103+
[-0.5*l*cos(head_width), 0.5*l*sin(head_width)]; ...
104+
[0, 0]; ...
105+
[-0.5*l*cos(head_width), -0.5*l*sin(head_width)];
106+
]';
107+
108+
% affine matrix: rotate by arrow angle and translate to end of arrow
109+
barb_transformation = affine2d([...
110+
[cos(phi), sin(phi), 0]; ...
111+
[-sin(phi), cos(phi), 0]; ...
112+
[xdata(n) + 0.1*udata(n), ydata(n) + 0.1*vdata(n), 1];
113+
]);
114+
115+
% apply transformation to barb
116+
barb = transformPointsForward(barb_transformation, barb')';
117+
118+
% add barb to plot data
119+
obj.data{quiverIndex}.x(end+1) = barb(1,1); % point 1
120+
obj.data{quiverIndex}.y(end+1) = barb(2,1);
121+
obj.data{quiverIndex}.x(end+1) = barb(1,2); % point 2
122+
obj.data{quiverIndex}.y(end+1) = barb(2,2);
123+
obj.data{quiverIndex}.x(end+1) = barb(1,3); % point 3
124+
obj.data{quiverIndex}.y(end+1) = barb(2,3);
125+
obj.data{quiverIndex}.x(end+1) = nan; % insert blank line between successive barbs
126+
obj.data{quiverIndex}.y(end+1) = nan;
127+
end
128+
129+
%-------------------------------------------------------------------------%
130+
97131
%-scatter showlegend-%
98132
leg = get(quiver_data.Annotation);
99133
legInfo = get(leg.LegendInformation);

0 commit comments

Comments
 (0)