【问题标题】:Converting Cartesian Coordinates To Polar Coordinates - Matlab将笛卡尔坐标转换为极坐标 - Matlab
【发布时间】:2016-09-23 19:01:06
【问题描述】:

我在将笛卡尔坐标转换为极坐标,然后再返回笛卡尔坐标以确认我的初始转换成功的整个转换过程中遇到问题。

但是,由于某种原因,当我从第三象限用极坐标转换回笛卡尔坐标时,我的 x 和 y 值是错误的。

以我的这部分代码为例:

x = -2.075548439;
y = -2.481775416;

if x < 0 && y < 0 % QUAD 3

    radius = sqrt( (x^2) + (y^2) );
    theta = atand( (y*-1)/(x*-1) );
    theta = (270 - theta);
end

x = radius * cosd(theta); 
y = radius * sind(theta);

% answer: x = -2.481775416, and y = -2.075548439

其他三个象限内的所有其他x 和y 转换将x 和y 放回正确的顺序。

不过,这部分代码确实将x 和y 重新按正确顺序排列:

x = 3.130287009;
y = -0.50613326;

if x > 0 && y < 0 % QUAD 4

    radius = sqrt( (x^2) + (y^2) );
    theta = atand( (y*-1)/(x) );
    theta = (360 - theta);
end

x = radius * cosd(theta); 
y = radius * sind(theta);

% answer: x = 3.130287009, and y = -0.50613326

【问题讨论】:

    标签: matlab polar-coordinates cartesian-coordinates


    【解决方案1】:

    您无需检查特殊情况。以下代码正确地将任何象限中的点从笛卡尔坐标转换为极坐标。

    x = -2.075548439;
    y = -2.481775416;
    
    radius = sqrt( (x^2) + (y^2) );
    theta = atan2d( y, x );
    
    x = radius * cosd(theta); 
    y = radius * sind(theta);
    

    【讨论】:

    • 更容易的是,help cart2pol、help pol2cart,除非这是他的任务。
    • 谢谢,效果很好,大大缩短了我的脚本!我唯一要做的就是从 360 度中减去负角,以获得正角,然后将其复制并粘贴到 Excel 中以匹配我的其余数据。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多