Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
angles in a triangle

Subject: angles in a triangle

From: Gregory

Date: 16 Mar, 2012 17:15:17

Message: 1 of 4

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

Subject: angles in a triangle

From: Gregory

Date: 16 Mar, 2012 17:50:29

Message: 2 of 4

"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([V2-V1;V3-V1])),dot(V2-V1,V3-V1))/pi*180;
A2 = atan2(abs(det([V3-V2;V1-V2])),dot(V3-V2,V1-V2))/pi*180;
A3 = atan2(abs(det([V1-V3;V2-V3])),dot(V1-V3,V2-V3))/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.

Subject: angles in a triangle

From: Roger Stafford

Date: 16 Mar, 2012 20:22:18

Message: 3 of 4

"Gregory" wrote in message <jjvuh5$90o$1@newscl01ah.mathworks.com>...
> "Gregory" wrote in message <jjvsf5$1ht$1@newscl01ah.mathworks.com>...
> > ......
> > 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.
> .......
> A1 = atan2(abs(det([V2-V1;V3-V1])),dot(V2-V1,V3-V1))/pi*180;
> A2 = atan2(abs(det([V3-V2;V1-V2])),dot(V3-V2,V1-V2))/pi*180;
> A3 = atan2(abs(det([V1-V3;V2-V3])),dot(V1-V3,V2-V3))/pi*180;
- - - - - - - - - -
  You've got the right formula and moreover your angles are correct. It's your plotting that is at fault. That third angle is actually an obtuse, not acute, angle. It is greater than ninety degrees. It has to be so that the three angles can sum to 180 degrees. Try plotting it again very carefully on a larger graph.

Roger Stafford

Subject: angles in a triangle

From: Gregory

Date: 16 Mar, 2012 22:34:21

Message: 4 of 4

"Roger Stafford" wrote in message <jk07dq$api$1@newscl01ah.mathworks.com>...
> "Gregory" wrote in message <jjvuh5$90o$1@newscl01ah.mathworks.com>...
> > "Gregory" wrote in message <jjvsf5$1ht$1@newscl01ah.mathworks.com>...
> > > ......
> > > 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.
> > .......
> > A1 = atan2(abs(det([V2-V1;V3-V1])),dot(V2-V1,V3-V1))/pi*180;
> > A2 = atan2(abs(det([V3-V2;V1-V2])),dot(V3-V2,V1-V2))/pi*180;
> > A3 = atan2(abs(det([V1-V3;V2-V3])),dot(V1-V3,V2-V3))/pi*180;
> - - - - - - - - - -
> You've got the right formula and moreover your angles are correct. It's your plotting that is at fault. That third angle is actually an obtuse, not acute, angle. It is greater than ninety degrees. It has to be so that the three angles can sum to 180 degrees. Try plotting it again very carefully on a larger graph.
>
> Roger Stafford

Ah Drats!

thanks so much for the help Roger! I just realised the scale of the axes were different hence the graph was skewed.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us