使用vb.net Math对象时出错 [英] Errors in using vb.net Math objects

查看:70
本文介绍了使用vb.net Math对象时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码集来计算航线,从纬度/经度,初始方向,转弯方向,航迹长度,航迹宽度和行数开始计算。



所有变量都定义为十进制数。


使用135度和315度,100英里的轨道,我得到2个不同的结果。东南航道点相距100.5671英里,西北航点相距99.23002英里。这会使我的飞行线开始和结束偏斜,但是线路是平行的。


在使用90/270标题进行测试时,如果线路较长,那么纬度/经度对似乎会导致标题的1.1度差异,但计算相同的路径长度和经度,但经度不同,因此航线不平行



以下是公式


致电GetNextLineStart(EndLatRadians,EndLonRadians,TrackWidthKM,ConnectingCourseRadians)

            LineStartLatDD = rad2deg(EndLatRadians)

            LineStartLonDD = rad2deg(EndLonRadians)

            LineCourseRadians = deg2rad(LineCourseDD)调用GetNextLineStart(EndLatRadians,EndLonRadians,TrackLengthKM,LineCourseRadians)

            LineEndLatDD = rad2deg(EndLatRadians)

            LineEndLonDD = rad2deg(EndLonRadians)



和 



Sub GetNextLineStart(Lat1,Lon1,Dist,Course )

        '以弧度为单位的纬度,以km为单位的dist,以弧度表示的当然价格为
       致电GetNewlat(Lat1,Lon1,Dist,Course)

       致电GetNewlon(Lat1,Lon1,Dist,Course)

        NewEndLatDD = RadToDeg(EndLatRadians)

        NewEndLonDD = RadToDeg(EndLonRadians)



   结束分

$
和真正的肉



Sub GetNewlat(Lat1,Lon1,Dist,Bearing)

        Dim R As Decimal = 6378.1

        EndLatRadians = Math.Asin(Math.Sin(Lat1)* Math.Cos(Dist / R)+ Math.Cos(Lat1)* Math.Sin(Dist / R)* Math.Cos(Bearing))

   结束分
    Sub GetNewlon(Lat1,Lon1,Dist,Bearing)

        Dim R As Decimal = 6378.1

        EndLonRadians = Lon1 + Math.Atan2(Math.Sin(方位)* Math.Sin(Dist / R)* Math.Cos(Lat1),Math.Cos(Dist / R) - Math.Sin(Lat1)* Math.Sin (Lat1))

   结束点¥



Robert Franklin

I have a code set that calculates flightlines, starting with a lat/lon, initial direction, turn direction, track length,track width And line count.

All variables are defined as decimal

Using 135 degrees and 315 degrees, 100 mile track, I get 2 different results. The southeast course points are 100.5671 miles apart, and the Northwest points are 99.23002 miles apart. This skews my flight lines start and ends, but the lines are parallel

In testing with 90/270 headings, with longer lines, the lat/lon pairs seem to cause a 1.1 degree variance in headings, but calculate to the same path lengths and longitudes, but differing longitudes so the flight lines are not parallel

Here are the formulas

Call GetNextLineStart(EndLatRadians, EndLonRadians, TrackWidthKM, connectingCourseRadians)
            LineStartLatDD = rad2deg(EndLatRadians)
            LineStartLonDD = rad2deg(EndLonRadians)
            LineCourseRadians = deg2rad(LineCourseDD)Call GetNextLineStart(EndLatRadians, EndLonRadians, TrackLengthKM, LineCourseRadians)
            LineEndLatDD = rad2deg(EndLatRadians)
            LineEndLonDD = rad2deg(EndLonRadians)

And 

Sub GetNextLineStart(Lat1, Lon1, Dist, Course)
        ' lat lon in radians, dist in km, course in radians
        Call GetNewlat(Lat1, Lon1, Dist, Course)
        Call GetNewlon(Lat1, Lon1, Dist, Course)
        NewEndLatDD = RadToDeg(EndLatRadians)
        NewEndLonDD = RadToDeg(EndLonRadians)

    End Sub

And the real meat

Sub GetNewlat(Lat1, Lon1, Dist, Bearing)
        Dim R As Decimal = 6378.1
        EndLatRadians = Math.Asin(Math.Sin(Lat1) * Math.Cos(Dist / R) + Math.Cos(Lat1) * Math.Sin(Dist / R) * Math.Cos(Bearing))
    End Sub
    Sub GetNewlon(Lat1, Lon1, Dist, Bearing)
        Dim R As Decimal = 6378.1
        EndLonRadians = Lon1 + Math.Atan2(Math.Sin(Bearing) * Math.Sin(Dist / R) * Math.Cos(Lat1), Math.Cos(Dist / R) - Math.Sin(Lat1) * Math.Sin(Lat1))
    End Sub


Robert Franklin

推荐答案

Robert,

Robert,

展望未来,请在发布代码时使用代码阻止工具。

Going forward, please use the code block tool when you post code.

*****

很难知道问题出在哪里,但是我会猜测度数到弧度的精度(反之亦然)不够高。

It's hard to know where the problem is but I'll hazard a guess that the precision in the degrees-to-radians (and vice versa) isn't high enough.

确保那些没有完成双打;改为使用十进制。

Make sure those aren't done with doubles; use Decimal instead.

也要知道这一点:大多数数学类使用双精度而不是十进制,所以有一些精度部分你不能做任何事情关于。

Do know this also: Most of the math class uses double precision, not decimal, so there's some parts of precision that you're not going to be able to do anything about.

我知道有些第三方库使用更高的精度,但我对它们没有任何经验。

I know there are third-party libraries out there that use a higher precision, but I don't have any experience with them.


这篇关于使用vb.net Math对象时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆