c#如何从水平和垂直度数中获取XYZ坐标

c# How to get XYZ coordinates from horizontal and vertical degrees

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

详细问题:如何让这段代码正常工作,使其 returns 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;
    }

您似乎有 spherical coordinate 并且想要获得笛卡尔坐标。在这种情况下

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

这里fi是你的"horizontal angle",theta是"vertical angle",x0..z0是原点坐标

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

    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是'horizontal'或'azimuth'角度(在x-y平面中与x轴的角度),phi是'inclination'(从正面角度 z 轴)或 'vertical' angle.The radius 是到笛卡尔坐标中给定点 (x,y,z) 的距离。