Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: Coping with asymptotes in tan function Date: Tue, 7 Dec 2010 20:35:29 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 18 Message-ID: <idm5qh$7fc$1@fred.mathworks.com> References: <idlsbt$9ip$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-03-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1291754129 7660 172.30.248.38 (7 Dec 2010 20:35:29 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Tue, 7 Dec 2010 20:35:29 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:693394 "Jane " <j.l.terry@hotmail.co.uk> wrote in message <idlsbt$9ip$1@fred.mathworks.com>... > Hi, I have written a function (probably not very efficiently) to measure the distance along a line, defined by the angle from the negative y-axis and passing through a known point. > > The problem I am having is coping with instance where the user selects the angle phi = [0, 90, 180, 270,...] the problem becoems ill-conditioned. I'm sure there must be an easy work around for this, but I've become so bogged down in the details I can't see it! > > I would appreciate any help. >....... - - - - - - - - You are making a hard job out of a very easy problem, Jane. In effect, you are rotating to a new coordinate system with a changed origin. The equations for that are: v = (y-ey)*cos(phi) - (x-ex)*sin(phi) u = (y-ey)*sin(phi) + (x-ex)*cos(phi) where (x,y) are the coordinates of the grid point in question, phi is the angle measured counterclockwise from the positive y-axis to the "centre plume line", (ex,ey) are the coordinates of the "emission source", and u and v are the requested orthogonal distance and distance along the plume line, respectively. Note that u and v are signed quantities which can be either positive or negative depending on the coordinates x and y. If you wish phi to measured clockwise, just change the signs of the sin(phi) in the above equations. If you wish to switch the directions u or v are to be measured in, just switch their signs in the equations accordingly. You were not specific on this point. Roger Stafford