0

我使用此代码从极坐标转换为笛卡尔坐标,反之亦然:

    final double alpha = Math.atan2(y - originY, x - originX);
    final int checkx = originX + (int) (radiusW * (Math.cos(alpha)));
    final int checky = originY + (int) (radiusH * (Math.sin(alpha)));
    final double newAlpha = Math.atan2(checky - originY, checkx - originX);
    double fault = Math.toDegrees(newAlpha) - Math.toDegrees(alpha);

使用这个,我得到可以达到15度的故障,它可以更好吗?

谢谢!

编辑 :

    final double alpha = Math.atan2(y - originY, x - originX);
    final double checkx = originX +  (radiusW * (Math.cos(alpha)));
    final double checky = originY +  (radiusH * (Math.sin(alpha)));
    final double newAlpha = Math.atan2(checky - originY, checkx - originX);
    double fault = Math.toDegrees(newAlpha) - Math.toDegrees(alpha);

试过还是一样的错误...

例如 :

public static void main(String[] args) {
    int originY = 700;
    int originX = 500;
    int radiusW = 500;
    int radiusH = 700;
    int y = 800;
    int x = 600;
    final double alpha = Math.atan2(y - originY, x - originX);
    final double checkx = originX + (radiusW * (Math.cos(alpha)));
    final double checky = originY + (radiusH * (Math.sin(alpha)));
    final double newAlpha = Math.atan2(checky - originY, checkx - originX);
    System.out.println(Math.toDegrees(newAlpha) - Math.toDegrees(alpha));
}

输出 :

9.462322208025618

4

0 回答 0