English 中文(简体)
正常的 com,从一开始至尾,作为牙、奶牛
原标题:Normalised compass bearing from start to end point as lat, lng pairs
  • 时间:2011-11-16 15:49:10
  •  标签:
  • math
  • vb6

净额:

at ......+π (即180°......+180°)) 实现折合结果的正常化(在360度之间,在180° ......360度之间,现值变为180° ......360度),转化成学位,然后使用(θ+360)360 %,其中60%为模块。

我用VB6和我的代码照此办理。

brng = (θ + 360) Mod 360

where=68

答案为292°,但预期回答为248°。

am i committing a mistake..? or am I missing something.? Please help me.

<>Update:

我要进一步解释我的问题,

Dim b As Double
Dim x As Double 
Dim y As Double 
Dim Dlat As Double 
Dim DLon As Double

Private Const pi As Double = 3.14159265358979

Public Function Atn2(ByVal y As Double, ByVal x As Double) As Double
    On Error GoTo DivideError
    Atn2 = Atn(y / x)
    If (x < 0) Then
        If (y < 0) Then Atn2 = Atn2 - vbPI Else Atn2 = Atn2 + vbPI
    End If
    Exit Function

DivideError:
    If Abs(y) > Abs(x) Then    Must be an overflow
        If y > 0 Then Atn2 = vbPI / 2 Else Atn2 = -vbPI / 2
    Else
        Atn2 = 0    Must be an underflow
    End If
    Resume Next
End Function


Public Sub AFAMP()
    lat1 = Val(Text1.Text) * pi / 180  conveting to radians
    lat2 = Val(Text2.Text) * pi / 180
    Long1 = Val(Text3.Text) * pi / 180
    Long2 = Val(Text4.Text) * pi / 180
    Dlat = (lat1 - lat2)
    DLon = (Long1 - Long2)
    y = Math.Sin(DLon) * Math.Cos(lat2)
    x = Math.Cos(lat1) * Math.Sin(lat2) - Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(DLon)
    b = Atn2(y, x) * (180 / pi)
    Text5.Text = (b +360) mod 360
End Sub

坐标如下:

lat1 = Val(7.337361) * pi / 180 

lat2 = Val(7.000667) * pi / 180

Long1 = Val(81.626198) * pi / 180

Long2 = Val(80.773737) * pi / 180

我用在线协调计算器,回答为248。 我的情况是292度。 谁能帮助我? 我 st。

问题回答

正如Deanna在评论中所说的那样,292个是正确的答案。 68 + 360 = 292

该法典是 Java,因为我可以记住VB syntax。

斜度。 不要重复这一法典,使之成为编号方法。 或者具有两个参数的头等功能,无论贵国的语文如何支持。

  Number.prototype.toDegrees = function (unit) {
    const u = (unit || "d").toLowerCase().charAt(0);
    switch (u) {
      case  r : //radians
        return this * 180 / Math.PI;
      case  g : //grads
        return this * 200 / Math.PI;
      case  d : //degrees
        return this;
      default: //radians
        return this * 180 / Math.PI;
    }
  };

平均范围。

Number.prototype.toNormalisedDegrees = function () {
  return (this - 360 * (Math.trunc(this / 360) - 1)) % 360;
}

浏览90度,扭转方向。

  Number.prototype.toCompassBearing = function (unit) {
    const degrees = unit && unit.toLowerCase().charAt(0) === "r" ? this.toDegrees() : this;
    return (90 - degrees).toNormalisedDegrees();
  }

Test with some known values

Number.prototype.toDegrees = function (unit) {
  const u = (unit || "d").toLowerCase().charAt(0);
  switch (u) {
case  r :
  return this * 180 / Math.PI;
case  g :
  return this * 200 / Math.PI;
default:
  return this;
  }
};
Number.prototype.toNormalisedDegrees = function () {
  return (this - 360 * (Math.trunc(this / 360) - 1)) % 360;
}
Number.prototype.toCompassBearing = function (unit) {
  return (90 - this.toDegrees(unit)).toNormalisedDegrees();
}

console.log(`0 cartesian (E) => ${(0).toCompassBearing("d")} compass bearing`);
console.log(`90 cartesian (N) => ${(90).toCompassBearing("d")} compass bearing`);
console.log(`90-22.5 cartesian (NNE) => ${(90-22.5).toCompassBearing("d")} compass bearing`);
console.log(`180 cartesian (W) => ${(180).toCompassBearing("d")} compass bearing`);
console.log(`-68 cartesian => ${(-68).toCompassBearing("d")} compass bearing`);
console.log(`-68 compass bearing => ${(-68).toNormalisedDegrees()} normalised degrees`);
console.log(`270 cartesian (S) => ${(270).toCompassBearing("d")} compass bearing`);
console.log(`0 cartesian (E) => ${(0).toCompassBearing("r")} compass bearing`);
console.log(`PI/2 cartesian (N) => ${(0.5 * Math.PI).toCompassBearing("r")} compass bearing`);
console.log(`PI cartesian (W) => ${Math.PI.toCompassBearing("r")} compass bearing`);
console.log(`1.5 PI cartesian (S) => ${(1.5 * Math.PI).toCompassBearing("r")} compass bearing`);
console.log(`2 PI cartesian (E) => ${(2 * Math.PI).toCompassBearing("r")} compass bearing`);
console.log(`20 PI cartesian (E) => ${(20 * Math.PI).toCompassBearing("r")} compass bearing`);
console.log(`-2 PI cartesian (E) => ${(-2 * Math.PI).toCompassBearing("r")} compass bearing`);
console.log(`-2.5 PI cartesian (S) => ${(-2.5 * Math.PI).toCompassBearing("r")} compass bearing`);
console.log(`-3 PI cartesian (W) => ${(-3 * Math.PI).toCompassBearing("r")} compass bearing`);
console.log(`-3.5 PI cartesian (N) => ${(-3.5 * Math.PI).toCompassBearing("r")} compass bearing`);

If 292 is right, what s this 248 business?

您询问如何将客体标题改为正常程度,但你提供的样本代码以及你认为正确的结果都表明,你实际上想要做的是确定拉坦、Lng pairs的起始点和终点点所确定的标题,并以正常程度表示。

There s an article here suggesting a method and your code looks like a botched attempt to implement this.

如果你在 Java文中正确的话,就是这样。

Number.prototype.toDegrees = function(unit) {
  const u = (unit || "d").toLowerCase().charAt(0);
  switch (u) {
    case  r :
      return this * 180 / Math.PI;
    case  g :
      return this * 200 / Math.PI;
    default:
      return this;
  }
};
Number.prototype.toRadians = function() {
  return this * Math.PI / 180;
}
Number.prototype.toNormalisedDegrees = function() {
  return (this - 360 * (Math.trunc(this / 360) - 1)) % 360;
}

function bearing(lat1, lng1, lat2, lng2) {
  const X = Math.cos(lat2) * Math.sin(lng2 - lng1);
  const Y = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lng2 - lng1);
  return Math.atan2(X, Y);
}

const lat1 = (7.337361).toRadians();
const lng1 = (81.626198).toRadians();
const lat2 = (7.000667).toRadians();
const lng2 = (80.773737).toRadians();
const bearingRadians = bearing(lat1, lng1, lat2, lng2);
const bearingDegrees = bearingRadians.toDegrees("radians");

console.log(`bearingRadians = ${bearingRadians}`);
console.log(`bearingDegrees = ${bearingDegrees}`);
console.log(`normalisedDegrees = ${bearingDegrees.toNormalisedDegrees()}`);

有两点值得注意。

  • Latitude and Longitude are in the compass frame of reference and do not require conversion from the cartesian frame of reference.
  • This code is written so that the result is in the compass frame of reference.
  • The result is in radians and then converted to degrees.
  • The degrees are then normalised to the 0-360 range.
  • Using your inputs I get your expected output.




相关问题
Prevent windows from queuing shellexecute requests

Win.ShellExecute 0, "open", "C:dirprogram.exe", "arguments", vbNullString, SW_SHOWNORMAL Win.ShellExecute 0, "open", "http://www.google.com", vbNullString, vbNullString, SW_SHOWNORMAL I want google....

Why is My Loop Only Deleting One File?

Using VB6 In a folder, i have n number of files, i want to delete a 0 kb files code Dim filename5 As String filename5 = Dir$(txtsourcedatabasefile & "*_*", vbDirectory) MsgBox filename5 Do ...

How to check the filesize?

Using VB6 I have the text file with different sizes, so i want to delete the file where filesize = 0 kb. How to make a vb6 code for deleting the 0 kb files. Need vb6 code Help

File Rename problem?

I m using VB6 and I have a folder where I have n number of files. I want to change the file extension to .txt. I used the code below to change the extension of all .fin files to .txt. Dim filename1 ...

Error 20728-F while in using Crystal Reports in VB6

I m using Crystal Reports in my VB6 project, but I m facing error while loading the report in crystalreport1.action=1; Please give me some solution for this problem. It is showing the error as Error ...

DllRegisterServer entry point was not found

When running my vb6 application I am getting error like, runtime error 53 : file not found: rscomclNoMsg.dll then i tried to register that dll from cmd line using regsvr32. Then I am getting ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签