【问题标题】:c# How to get XYZ coordinates from horizontal and vertical degreesc#如何从水平和垂直度数获取XYZ坐标
【发布时间】:2018-01-26 20:28:39
【问题描述】:

在过去的一个小时里,我一直在努力让这段代码正常工作,我几乎完成了。一切正常,但float verticalDegrees

详细问题:如何让这段代码正常工作,以便从水平度数、垂直度数、半径和原点返回 XYZ?

This link helped me, but it's missing Z coordinate

这是我目前所拥有的:

    private float[] DegreesToXYZ(float horizonalDegrees, float verticalDegrees, float radius, float[] origin)
    {
        float[] xyz = new float[3];
        double radiansH = horizonalDegrees * Math.PI / 180.0;
        double radiansV = verticalDegrees * Math.PI / 180.0;

        xyz[1] = (float)Math.Cos(radiansH) * radius + origin[1];
        xyz[0] = (float)Math.Sin(-radiansH) * radius + origin[0];
        double deltaXY = Math.Sqrt(origin[0] * origin[0] + origin[1] * origin[1]);
        xyz[2] = (float)Math.Atan2(origin[2], deltaXY);
        return xyz;
    }

【问题讨论】:

    标签: c# math coordinates degrees


    【解决方案1】:

    此方法将球坐标转换为笛卡尔坐标:

        private static double[] DegreesToXYZ(double radius, double theta, double phi, double[] originXYZ)
        {
            theta *= Math.PI / 180;//converting degress into radians
            phi *= Math.PI / 180;//converting degress into radians
    
            double[] xyz = new double[3];
    
            xyz[0] = originXYZ[0] + radius * Math.Cos(theta) * Math.Sin(phi);//x
            xyz[1] = originXYZ[1] + radius * Math.Sin(theta) * Math.Sin(phi);//y
            xyz[2] = originXYZ[2] + radius * Math.Cos(phi);//z
    
            return xyz;
        }
    

    其中theta 是“水平”或“方位角”角(与 x-y 平面中 x 轴的角度),phi 是“倾角”(与正 z 轴)或“垂直”角度。radius 是到笛卡尔坐标中给定点 (x,y,z) 的距离。

    【讨论】:

    • 它似乎在工作,虽然水平和垂直是倒置的。例如:当我转动时,它会向相反的方向移动。我该如何解决这个问题?
    【解决方案2】:

    似乎你有spherical coordinates 并且想要获取笛卡尔坐标。在这种情况下

     x = x0 + r * Cos(fi)  * Sin(theta)
     y = y0 + r * Sin(fi)  * Sin(theta)
     z = z0 + r * Cos(theta)
    

    这里fi是你的“水平角”,theta是“垂直角”,x0..z0是原点坐标

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-10
      • 2017-05-21
      • 1970-01-01
      • 1970-01-01
      • 2021-08-16
      相关资源
      最近更新 更多