Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Speedup: Fast polar intersection
Date: Sat, 16 Apr 2011 03:05:20 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 30
Message-ID: <iob11g$ao3$1@fred.mathworks.com>
References: <inv061$f7p$1@fred.mathworks.com> <io8oa4$gc5$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1302923120 11011 172.30.248.47 (16 Apr 2011 03:05:20 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 16 Apr 2011 03:05:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:722166

"Roger Stafford" wrote in message <io8oa4$gc5$1@fred.mathworks.com>...
>   I finally got back to your problem, Johannes.  I realize now that there is no ....
- - - - - - - -
  I vectorized the logic that was in the previous for-loop.  Perhaps it will help the speed.  At least it looks a little neater.

n = size(a,1);
r = zeros(n,1);
[as,p] = sort(a);
ca = cos(as); sa = sin(as);
s = repmat((1:n).',2,1);
m = size(xy,1);
x = xy(:,1); y = xy(:,2);
dx = diff(x); dy = diff(y);
num = x(1:m-1).*dy-y(1:m-1).*dx;
axy = atan2(y,x);
[~,b] = histc(axy,[-inf;as;inf]);
t1 = abs(diff(axy)) >= pi;
b1 = b(1:m-1); b2 = b(2:m);
t2 = ((b1<b2)==t1);
c1 = t2.*(b2-b1)+b1;
c2 = t2.*(b1-b2)+b2+t1.*n-1;
m1 = 1:m-1;
for k = m1(c1<=c2)
 t = s(c1(k):c2(k));
 u = num(k)./(ca(t)*dy(k)-sa(t)*dx(k));
 r(t) = max(r(t),u);
end
r(p) = r;

Roger Stafford