数学/三角运算以获得C#中倾斜椭圆的XYZ坐标

本文关键字:倾斜 坐标 XYZ 三角 运算 数学 | 更新日期: 2023-09-27 18:20:55

我需要得到位于倾斜平面上的椭圆上的点的坐标。椭圆也在XY平面中旋转。我能够获得沿旋转的水平椭圆的点的正确X和Y坐标,以及倾斜椭圆的水平投影的X和Y点,但无法计算出获得倾斜椭圆上点的Z值所需的数学/三角图。我试图通过使用从椭圆中心到倾斜椭圆上每个点的向量的视倾角来实现这一点。

这是我正在使用的代码:

class ellipsoid
{
    public ellipsoid() { }
    public double bearing { get; set; }
    public double plunge { get; set; }
    public double dip { get; set; }
    public double x { get; set; }
    public double y { get; set; }
    public double z { get; set; }
}
class exampleCalc
{
    public void createDippingEllipse(ellipsoid ellipsoid, double majorAxis, double semiMajorAxis)
    // majorAxis is the longest axis, semiMajorAxis is the shorter axis
    {
        double semiMajorAxisApparent = 0;
        Int32 strNum = 1;
        point delta = new point();
        point horz = new point();
        point ep = new point();
        point p = new point();
        p.x = ellipsoid.x;
        p.y = ellipsoid.y;
        p.z = ellipsoid.z;
        // az represents the angular interval along which points will be located
        for (Int32 az = 0; az <= 360; az = az + 10)
        {
            double rakeAngle = 0;
            if (az >= 0 && az <= 90)
            {
                rakeAngle = az;
            }
            if (az > 90 && az <= 180)
            {
                rakeAngle = 180 - az;
            }
            if (az > 180 && az <= 270)
            {
                rakeAngle = az - 180;
            }
            if (az > 270 && az <= 360)
            {
                rakeAngle = 360 - az;
            }
            if (ellipsoid.dip == 90)
            {
                semiMajorAxisApparent = semiMajorAxis;
            }
            else
            {
                semiMajorAxisApparent = semiMajorAxis * Math.Cos(ep.degreesToRadians(Math.Abs(ellipsoid.dip)));
            }
            double cosAz = Math.Cos(ep.degreesToRadians(az));
            double sinAz = Math.Sin(ep.degreesToRadians(az));
            // convert mathematical bearing to bearing where north is zero
            double bearing0north = ellipsoid.bearing + 90;
            if (bearing0north > 360) { bearing0north = 360 - bearing0north; }
            double cosBearing = Math.Cos(ep.degreesToRadians(bearing0north));
            double sinBearing = Math.Sin(ep.degreesToRadians(bearing0north));
            // delta.x and delta.y are correct
            delta.x = (majorAxis * cosBearing * cosAz) - (semiMajorAxisApparent * sinBearing * sinAz);
            delta.y = (majorAxis * cosAz * sinBearing) + (semiMajorAxisApparent * sinAz * cosBearing);
            double horzDist = Math.Sqrt(Math.Pow(delta.x, 2) + Math.Pow(delta.y, 2));
            // uncorrected for apparent horz length
            horz.x = (majorAxis * cosBearing * cosAz) - (semiMajorAxis * sinBearing * sinAz);
            horz.y = (majorAxis * cosAz * sinBearing) + (semiMajorAxis * sinAz * cosBearing);
            double apparentDip = Math.Atan(Math.Tan(ep.degreesToRadians(Math.Abs(ellipsoid.bearing))) * Math.Sin(ep.degreesToRadians(rakeAngle)));
            // delta.z is not correct
            delta.z = horzDist * Math.Atan(apparentDip);
            ep.x = p.x + delta.x;
            ep.y = p.y + delta.y;
            ep.z = p.z + delta.z;
        }
    }
}

数学/三角运算以获得C#中倾斜椭圆的XYZ坐标

您确实在尝试一个相对简单的问题的最复杂的可能解决方案(除了选择非惯性系)。

简单地解决位于X-Y平面上的椭圆中关于原点的所有数学问题,并计算将椭圆平移和旋转到所需位置和方向的仿射矩阵。然后简单地将矩阵应用于每个计算点,以获得正确的定向点。