首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java中Vincenty公式的不寻常格式

Java中Vincenty公式的不寻常格式
EN

Stack Overflow用户
提问于 2022-09-27 09:25:38
回答 1查看 15关注 0票数 0

我正在接管一个项目,并且注意到,当使用vincenty公式时,它是以一种不寻常的方式编写的。它是这样写的:

代码语言:javascript
复制
    String direct(double distance, double initialBearing, double positionlat, double positionlong)  {
        // if (this.height != 0) throw new RangeError('point must be on the surface of
        // the ellipsoid');

        double φ1 = this.toRad(positionlat)/* .toRadians() */, λ1 = this.toRad(positionlong)/* .toRadians() */;
        double α1 = this.toRad(initialBearing);
        double s = distance;

        // allow alternative ellipsoid to be specified
        // double ellipsoid = /*this.datum ? this.datum.ellipsoid :*/
        // LatLonEllipsoidal.ellipsoids.WGS84;
        // const {a, b, f} = ellipsoid;
        double a = 6378137;
        double b = 6356752.314245;
        double f = 1 / 298.257223563;
        // double a = ellipsoid;
        // double b = ellipsoid;
        // double f = ellipsoid;

        double sinα1 = Math.sin(α1);
        double cosα1 = Math.cos(α1);

        double tanU1 = (1 - f) * Math.tan(φ1), cosU1 = 1 / Math.sqrt((1 + tanU1 * tanU1)), sinU1 = tanU1 * cosU1;
        double σ1 = Math.atan2(tanU1, cosα1); // σ1 = angular distance on the sphere from the equator to P1
        double sinα = cosU1 * sinα1; // α = azimuth of the geodesic at the equator
        double cosSqα = 1 - sinα * sinα;
        double uSq = cosSqα * (a * a - b * b) / (b * b);
        double A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)));
        double B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)));

        double σ = s / (b * A);
        Double sinσ = null, cosσ = null, Δσ = null; // σ = angular distance P� P₂ on the sphere
        Double cos2σₘ = null; // σₘ = angular distance on the sphere from the equator to the midpoint of the
                                // line

        Double σʹ = null, iterations = 0d;
        do {
            cos2σₘ = Math.cos(2 * σ1 + σ);
            sinσ = Math.sin(σ);
            cosσ = Math.cos(σ);
            Δσ = B * sinσ * (cos2σₘ + B / 4 * (cosσ * (-1 + 2 * cos2σₘ * cos2σₘ)
                    - B / 6 * cos2σₘ * (-3 + 4 * sinσ * sinσ) * (-3 + 4 * cos2σₘ * cos2σₘ)));
            σʹ = σ;
            σ = s / (b * A) + Δσ;
        } while (Math.abs(σ - σʹ) > 1e-12 && ++iterations < 100);
        if (iterations >= 100) {
            //throw new Exception("Vincenty formula failed to converge"); // not possible?
            System.err.println("Warning: Vincenty formula failed to converge!");
        }
        

        double x = sinU1 * sinσ - cosU1 * cosσ * cosα1;
        double φ2 = Math.atan2(sinU1 * cosσ + cosU1 * sinσ * cosα1, (1 - f) * Math.sqrt(sinα * sinα + x * x));
        double λ = Math.atan2(sinσ * sinα1, cosU1 * cosσ - sinU1 * sinσ * cosα1);
        double C = f / 16 * cosSqα * (4 + f * (4 - 3 * cosSqα));
        double L = λ - (1 - C) * f * sinα * (σ + C * sinσ * (cos2σₘ + C * cosσ * (-1 + 2 * cos2σₘ * cos2σₘ)));
        double λ2 = λ1 + L;

        double α2 = Math.atan2(sinα, -x);

        // const destinationPoint = new
        // LatLonEllipsoidal_Vincenty(this.toDeg(φ2)/*.toDegrees()*/,
        // this.toDeg(λ2)/*.toDegrees()*/, 0, undefined);

        return this.toDeg(φ2) + ";" + this.toDeg(λ2);/*
                                                         * { lat: this.toDeg(φ2), lng: this.toDeg(λ2)
                                                         */
        /*
         * destinationPoint.g point: destinationPoint, finalBearing:
         * Dms.wrap360(this.toDeg(α2)/*.toDegrees()
         *//*
             * ), iterations: iterations,
             */
        // };
    }

现在IDE (eclipse)正在响应,它无法处理变量名,例如φ1。是否有一个优雅的解决方案来解决这个问题,还是我必须重写它?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-27 09:39:56

很可能,源代码是用UTF-8编码编写的,您的Eclipse被配置为将源代码解释为ANSI、ISO-8859-1、cp1252或类似的代码。

然后,您看到的φ实际上是希腊字符phi (φ)的两字节UTF-8表示形式,根据ANSI解释。

配置Eclipse以期待UTF-8编码(Preferences / General / Workspace /文本文件编码),然后它应该能够编译。

这个例子说明了为什么即使在今天在源代码中使用ASCII之外的字符也是个坏主意。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73865235

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档