【问题标题】:Math/Trig to get XYZ coordinates of dipping ellipse in C#数学/三角函数在 C# 中获取倾斜椭圆的 XYZ 坐标
【发布时间】:2014-09-07 22:48:53
【问题描述】:

我需要沿位于倾斜平面上的椭圆获取点的坐标。椭圆也在 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# trigonometry ellipse


    【解决方案1】:

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

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

    【讨论】:

    • 嗨彼得 - 感谢您的回复。我不熟悉仿射矩阵(尽管我现在会去做一些研究)。您愿意分享一些我可以用作示例的代码吗?
    • 我的 Hexgrid 游戏实用程序是开源的 - 只要您将我列为原作者即可使用:hexgridutilities.codeplex.com。虽然只有 2D,但 IntMatrix2D 和 IntVector2D 类可以帮助您入门。
    • 谢谢,Pieter - 我会看看。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多