-1

ユーザーが線を描くアプリケーションがあり、ソフトウェアは自動的に、線が直角の長方形の隣接する2辺の中点と交差する長方形を作成する必要があります。以下を参照してください。赤い線はユーザーが描いたもので、紫色の長方形は計算されたものです。私のアルゴリズムはほとんど機能しますが、いくつかの方向では長方形が直角ではありません。理由を知りたいのですが、コードにはかなりの量の近似値があり、使用するスケール (数 km) に基づいて問題ないはずです。地球の曲率なんて気にしなくていいのに。

コードを改善する方法を知っている人はいますか? ここに私の参照があります: ポイントの 緯度と経度をメートルに計算します

四角形をマップする

        public static MapRectangle CreatMapRectangle(BalingZone zone, double thickness)
    {
        MapsCoordinate rectpoint2;
        MapsCoordinate rectPoint1 ;
        MapsCoordinate rectPoint3 ;
        MapsCoordinate rectPoint4 ;

        var point1 = zone.Coordinates[0];
        var point2 = zone.Coordinates[1];

        var latitudeDiff = LatitudeDiffToMeters(point2.Latitude - point1.Latitude);
        var longitudeDiff = LongitudeDiffToMeters(point1.Longitude - point2.Longitude, point1.Latitude);
        var slopeB = longitudeDiff / latitudeDiff;

        double latOffset = thickness * (slopeB / Math.Sqrt(1 + slopeB * slopeB));
        double longOffset = thickness * (1 / Math.Sqrt(1 + slopeB * slopeB));


        double p3Lat = CalculateLatitude(point1.Latitude, latOffset);
        double p3Long = CalculateLongitude( point1.Longitude, p3Lat , longOffset);
        rectPoint1 = new MapsCoordinate(p3Lat, p3Long);


        double p4Lat = CalculateLatitude(point1.Latitude, -latOffset);
        double p4Long = CalculateLongitude(point1.Longitude, p4Lat, -longOffset);
        rectpoint2 = new MapsCoordinate(p4Lat, p4Long);


        double p5Lat = CalculateLatitude(point2.Latitude, latOffset);
        double p5Long = CalculateLongitude( point2.Longitude, p5Lat , longOffset);
        rectPoint4 = new MapsCoordinate(p5Lat, p5Long);

        double p6Lat = CalculateLatitude(point2.Latitude, -latOffset);
        double p6Long = CalculateLongitude( point2.Longitude, p6Lat , -longOffset);
        rectPoint3 = new MapsCoordinate(p6Lat, p6Long);

        return new MapRectangle(rectPoint4, rectPoint3, rectPoint1, rectpoint2, thickness);
    }

    //use the quick and dirty estimate that 111,111 meters (111.111 km) in the y direction is 1 degree (of latitude)
    // and 111,111 * cos(latitude) meters in the x direction is 1 degree (of longitude).

    private static double LatitudeDiffToMeters(double latitudeDiff)
    {
        return 111111.0 * latitudeDiff;
    }

    private static double LongitudeDiffToMeters(double longitudeDiff, double latitude)
    {
        return 111111.0*Math.Cos(latitude)*longitudeDiff;
    }


    private static double CalculateLatitude(double latitude, double offset)
    {
        return latitude + offset/111111.0;
    }

    private static double CalculateLongitude(double longitude, double latitude, double offset)
    {
        return longitude + offset/(111111.0*Math.Cos(latitude));
    }
}
4

1 に答える 1

0

質問が反対票を投じられた理由がわからない!とにかく、コードにエラーがありました。数学関数でラジアンの代わりに度を使用していました。また、球状の地球を想定するように計算を更新しました (極に近づくとうまく機能するため)。

private static double LatitudeDiffToMeters(double latitudeDiff)
    {
        return (R*latitudeDiff*Math.PI)/180;
    }

    private static double LongitudeDiffToMeters(double longitudeDiff, double latitude)
    {
        return (longitudeDiff*Math.PI* R * Math.Cos (Math.PI * latitude / 180))/180;
    }


    private static double CalculateLatitude(double latitude, double offset)
    {
        return latitude + ((offset/R) * (180/Math.PI));
    }

    private static double CalculateLongitude(double longitude, double latitude, double offset)
    {
        return longitude + offset / (R * Math.Cos (Math.PI * latitude / 180)) * (180 / Math.PI);
    }
于 2015-09-16T19:25:53.663 に答える