从笛卡尔坐标转换为对数极坐标
我想将笛卡尔系统中给出的一些点坐标转换为对数极坐标笛卡尔系统。
但是,我不确定如何很好地执行 atan 操作。
目前,我正在这样做,这看起来很丑陋。
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));
输入点位于 Xt 中,第一列是 X 坐标值,第二列是 Y 坐标值。 Xlp 包含对数极坐标,第一列对应于距离,第二列对应于角度。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我愿意吗
?
I'd do
?
使用 atan2() 为您完成所有这些艰苦的工作。
Use atan2() to do all this hard work for you.