"Gregory" wrote in message <jjvsf5$1ht$1@newscl01ah.mathworks.com>...
> Hi,
>
> I'm currently trying to write an algo to find the angles of a triangle.
>
> I've tried both the acos method and the atan2 method Roger Stafford suggested in a thread before, but the one of the angles always turn out to be pi  theta and not the theta im looking for.
>
> my vertices are
> a =
>
> 1 5
> 1 2
> 2 4
>
> and the angles i got (in degrees) ans =
>
> 45.0000 26.5651 108.4349.
>
> but when i plotted the graph, none of the angles were > 90 degrees.
>
> is there a way around this?
>
> Thanks!
> John
This is what I have down so far:
function theta = angletri(a)
%Calculates Angles of a Triangle from Vertices in the form (x y) from input
%a.
x=a(:,1);
y=a(:,2);
tri=delaunay(x,y);
tri=sortrows(tri);
triplot(tri,x,y)
for i = 1 : size(tri,1)
V1 = a(tri(i,1),:)
V2 = a(tri(i,2),:)
V3 = a(tri(i,3),:)
A1 = atan2(abs(det([V2V1;V3V1])),dot(V2V1,V3V1))/pi*180;
A2 = atan2(abs(det([V3V2;V1V2])),dot(V3V2,V1V2))/pi*180;
A3 = atan2(abs(det([V1V3;V2V3])),dot(V1V3,V2V3))/pi*180;
theta(i,:) = [ A1 A2 A3 ];
A1 + A2 + A3
end
end
I am currently testing it with just 1 triangle but it doesnt seem to give the correct angles.
