开发者

Converting from cartesian coordinates to log-polar coordinates

I want to convert some point coordinates which are given in a cartesian system to a log-polar cartesian system.

However, I'm not sure开发者_开发知识库 how to perform the atan operation nicely.

Currently, I'm doing it as follows, which seems to be pretty ugly.

   Xlp = zeros(n, 2);
   Xlp(:, 1) = log(sqrt(Xt(:, 1).^2 + Xt(:, 2).^2));
   sel = Xlp(:, 1) >= 0 && Xlp(:, 2) >= 0;
   Xlp(sel, 2) = atan(Xt(sel, 2) / Xt(sel, 1));
   sel = Xlp(:, 1) >= 0 && Xlp(:, 2) < 0;
   Xlp(sel, 2) = repmat(2*pi, size(sel), 1) + atan(Xt(sel, 2) / Xt(sel, 1));
   sel = Xlp(:, 1) < 0 && Xlp(:, 2) >= 0;
   Xlp(sel, 2) = repmat(pi, size(sel), 1) + atan(Xt(sel, 2) / Xt(sel, 1));
   sel = Xlp(:, 1) < 0 && Xlp(:, 2) < 0;
   Xlp(sel, 2) = repmat(pi, size(sel), 1) + atan(Xt(sel, 2) / Xt(sel, 1));

Input points are in Xt with the first column being the X coordinate values and the second column being the Y coordinate values. Xlp contains the logpolar coordinates given as the first column corresponding to the distance and the second column corresponding to the angle.


I'd do

[THETA,RHO] = cart2pol(X,Y)
RHO=log(RHO)

?


Use atan2() to do all this hard work for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜