From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Issues with atan2 function.. please advise!
Date: Mon, 8 Dec 2008 16:14:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 14
Message-ID: <ghjh4a$jqo$>
References: <>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1228752842 20312 (8 Dec 2008 16:14:02 GMT)
NNTP-Posting-Date: Mon, 8 Dec 2008 16:14:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 791003
Xref: comp.soft-sys.matlab:505633

me thinks its a logic problem, not atan2.  note that atan2 has a range of -pi to +pi.  when you compute theta and phi you are taking gamma (a product of atan2) which therefore has a range of -pi to +pi and adding/subtracting beta (a product of an asin) which has a range of -pi/2 to +pi/2.  so the lines:

theta = gamma - beta
phi = gamma + beta

can generate ranges of theta and phi from 3pi/2 to -3pi/2...

Then you calc ang from an atan2 so it has a range of -pi to pi, but you compare ang to theta and phi to determine if you are inside or outside the triangle... 

if ang <= theta || ang >= phi %tests of angle is less than theta

but in some cases theta and phi will be outside of the range of ang which seems to cut off part of the triangle.