Pergunta

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.

Foi útil?

Solução

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

Outras dicas

I'd do

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

?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top