Path: news.mathworks.com!not-for-mail 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$1@fred.mathworks.com> References: <6f0f0e86-f955-43bc-a085-588a9cea560e@j32g2000yqn.googlegroups.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-03-blr.mathworks.com Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1228752842 20312 172.30.248.38 (8 Dec 2008 16:14:02 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Mon, 8 Dec 2008 16:14:02 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 791003 Xref: news.mathworks.com 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.