Consider for the example the following points scatter:
x=[-1.6794 -2.6072 0.4175 0.1898 -0.7749 1.8392 1.7411];
y=[7.9969 9.5312 8.0302 7.2956 6.5550 9.9890 7.9462];
with a reference point :
xc = -0.9311; yc = 9.1109;
Plotting the scatter points:
figure(1)
hold on
scatter(x,y,'.b')
scatter(xc,yc,'.r')
xlim([-10 10]); ylim([0 15]);
I can calculate all the angles between all the vectors that start at [xc,yc]
in the following way:
v=[x-xc;y-yc]';
dot_v=v*v';
norm_v=sqrt(v(:,1).^2+v(:,2).^2);
angles=acosd(dot_v./(norm_v.*norm_v'));
The following plot will visualize the vectors and the angles between them:
figure(1)
hold on
scatter(x,y,'.b')
scatter(xc,yc,'.r')
xlim([-10 10]); ylim([0 15]);
for i=1:length(x)
for j=1:length(x)
hh1=plot([xc x(i)],[yc y(i)]);
hh2=plot([xc x(j)],[yc y(j)]);
th=title(num2str(angles(i,j)));
pause
delete(hh1); delete(hh2); delete(th);
end
end
I would like however to obtain all the angles in the trianle created by these two vectors, for example:
I can use loops and calculate the angles between each vector that is made out of two points in the data, however, the data I have contains a very large number of points, therefore I would like to avoid using loops and make use of matlab abilities in writing things in matrix form, therefore please provide an elegant and efficient answer.