【问题标题】:Degree doesnt get calculated correctly, where did i go wrong?度数计算不正确,我哪里出错了?
【发布时间】:2020-05-05 19:28:13
【问题描述】:

我正在编写一个程序,它获取 3d 坐标并将它们放置在 3d 地球上,然后投影到 2d 屏幕上。要围绕轴转动坐标,我想使用两个点的法线(起点和终点(飞行的)),将其转到 x3 轴,然后将其余点转动相同方式,最终计算点,我需要动画一个点,从点 A 到点 B。我用来把点放到地球上的矩阵是:

    public double[] genXYZ(double phi, double theta) {
    double[] coords3D = new double[3];
    phi = Math.toRadians(phi);
    theta = Math.toRadians(theta);
    coords3D[0] = Math.cos(theta) * Math.cos(phi);
    coords3D[1] = Math.cos(theta) * Math.sin(phi);
    coords3D[2] = Math.sin(theta);
    return coords3D;
}

一切正常。直到我尝试计算法线的 phi 和 theta 角(在我正确计算法线之后)。

public double[] getNAngles(double[] ncoords) {
    double[] NAngles = new double[2];
    NAngles[1] = Math.asin(Math.toRadians(ncoords[2]));
    NAngles[0] = Math.acos(ncoords[0] / Math.cos(NAngles[1]));
    NAngles[0] = Math.toDegrees(NAngles[0]);
    NAngles[1] = Math.toDegrees(NAngles[1]);
    System.out.println("N phi: " + NAngles[0]);
    System.out.println("N theta: " + NAngles[1]);
    return NAngles;
}

Globe

青色:开始(格林威治) 洋红色:结束(伊斯坦布尔) 黑色:正常 粉色:代码计算出来的,黑色有什么角度。

提前致谢!

【问题讨论】:

    标签: java math coordinates


    【解决方案1】:

    删除Math.toRadians 调用,因为coords 不是角度,它们是-1..1 范围内的无量纲值

    NAngles[1] = Math.asin(ncoords[2]);
    

    还可以考虑使用atan2 函数进行NAngles[0] 计算以排除符号效应和反余弦角限制(0..Pi)。

    NAngles[0] = Math.atan2(ncoords[1], ncoords[0]);
    

    【讨论】:

    • 我用 ncoords2 删除了 toRadians 并做了 atan2。我去看看atan2。似乎仍然没有加起来......
    • 您是否使用genXYZ 返回的coords[] 并获取另一个phi, theta 值?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多