當前正在學校項目中,我們必須編碼(在vb.net中)一個程序,該程序讀取具有不同點的x和y座標的txt文件,並在每兩個點之間進行距離計算,在文件上寫下距離。VB.NET .txt文件操作
txt文件看起來是這樣的:
596;226
506;179
412;298
583;291
...etc
,所以我的目標是計算dx和dy(座標每次2線之間的差值),所以我得到的距離之後。
唯一的問題是我被困在如何得到dx和dy(7天現在) 例如第1和第2行的例子是(506-596),第2行是(412-506)等等對於所有與dy的點。
這裏是我一直試圖徒勞(大部分代碼只是從網上覆制/粘貼)。
Imports System.IO
Public Class Form1
Private Sub FichierTexteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FichierTexteToolStripMenuItem.Click
OpenFileDialog1.Filter = "fichier texte| *.txt"
Dim nbLigne As Integer
nbLigne = 0
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim sr As StreamReader
sr = New StreamReader(OpenFileDialog1.FileName)
Dim x, y As String
Dim dx, dy As String
Dim txtTotal As Object
Dim ligne = sr.ReadLine()
Dim tabl() As Object
tabl = Split(ligne, ";") 'la taille de tableau represente le nombre de bloc qui ksont séparer par les separateur
txtTotal = ligne + vbCrLf
'While Not ligne Is Nothing
' ligne = sr.ReadLine
' txtTotal = txtTotal + ligne + vbCrLf
' tabl = Split(ligne, ";") 'la taille de tableau represente le nombre de bloc qui ksont séparer par les separateur
' nbLigne = nbLigne + 1
'End While
x = tabl(0)
y = tabl(1)
While Not ligne Is Nothing
ligne = sr.ReadLine
tabl = Split(ligne, ";")
dx = tabl(0) - x
dy = tabl(1) - y
End While
'test
Label2.Text = dx
Label3.Text = dy
'Label1.Text = Calculs.distance(dx, dy)
Else : Close()
End If
End Sub
End Class
謝謝你,希望有人會幫我出這個問題的:)
聽說過的[勾股定理]的(https://en.wikipedia.org/維基/ Pythagorean_theorem)?法文:[Théorèmede Pythagore](https://fr.wikipedia.org/wiki/Th%C3%A9or%C3%A8me_de_Pythagore)。您將需要它來計算2-D空間中2個點之間的距離! –
這不是一個如何計算我在模塊中完成論壇的問題,但我需要dx和dy。 dist = Math.Sqrt((dx)^ 2 +(dy)^ 2) – Goraby
你有''dx''和''dy''作爲字符串。要做任何類型的數學與他們,你需要改變他們整數(或單打或雙打) – RPM