📄 module1.bas
字号:
ReDim Part(Ct) As SearchLine
z = 1
PMax = 9999
g = 0
For k1 = 1 To Ct - 1
Debug.Print z, "z"
Part(z).Firstpointx = ft_fin.Parts.Item(1).Item(k1).X
Part(z).FirstPointY = ft_fin.Parts.Item(1).Item(k1).Y
Part(z).SecondPointX = ft_fin.Parts.Item(1).Item(k1 + 1).X
Part(z).SecondPointY = ft_fin.Parts.Item(1).Item(k1 + 1).Y
Debug.Print Part(z).Firstpointx, Part(z).FirstPointY, Part(z).SecondPointX, Part(z).SecondPointY, "fx,fy,sx,sy"
If Part(z).Firstpointx = Part(z).SecondPointX And Part(z).FirstPointY <> Part(z).SecondPointY Then
Part(z).ThirdPointX = Part(z).Firstpointx
Part(z).ThirdPointY = GpsY
ElseIf Part(z).FirstPointY = Part(z).SecondPointY And Part(z).Firstpointx <> Part(z).SecondPointX Then
Part(z).ThirdPointX = GpsX
Part(z).ThirdPointY = Part(z).FirstPointY
ElseIf Part(z).Firstpointx = Part(z).SecondPointX And Part(z).FirstPointY = Part(z).SecondPointY Then
Part(z).ThirdPointX = Part(z).Firstpointx
Part(z).ThirdPointY = Part(z).FirstPointY
Else
m1 = (Part(z).SecondPointY - Part(z).FirstPointY) / (Part(z).SecondPointX - Part(z).Firstpointx)
m2 = -1 / m1
Part(z).ThirdPointX = (GpsY - Part(z).FirstPointY + m1 * Part(z).Firstpointx - m2 * GpsX) / (m1 - m2)
Part(z).ThirdPointY = Part(z).FirstPointY + m1 * (Part(z).ThirdPointX - Part(z).Firstpointx)
End If
Debug.Print Part(z).ThirdPointX, Part(z).ThirdPointY, "tx,ty"
Debug.Print ((Form1.Map1.Distance(Part(z).ThirdPointX, Part(z).ThirdPointY, Part(z).Firstpointx, Part(z).FirstPointY) + Form1.Map1.Distance(Part(z).ThirdPointX, Part(z).ThirdPointY, Part(z).SecondPointX, Part(z).SecondPointY)) - Form1.Map1.Distance(Part(z).Firstpointx, Part(z).FirstPointY, Part(z).SecondPointX, Part(z).SecondPointY))
If (Form1.Map1.Distance(Part(z).ThirdPointX, Part(z).ThirdPointY, Part(z).Firstpointx, Part(z).FirstPointY) + Form1.Map1.Distance(Part(z).ThirdPointX, Part(z).ThirdPointY, Part(z).SecondPointX, Part(z).SecondPointY)) - Form1.Map1.Distance(Part(z).Firstpointx, Part(z).FirstPointY, Part(z).SecondPointX, Part(z).SecondPointY) < small Then
If Part(z).Firstpointx = Part(z).SecondPointX And Part(z).FirstPointY = Part(z).SecondPointY Then
Part(z).D = 9998
Else
Part(z).ThirdPointX = Part(z).ThirdPointX
Part(z).ThirdPointY = Part(z).ThirdPointY
If Part(z).SecondPointX = Part(z).Firstpointx Then
Part(z).Angle = 0
ElseIf Part(z).SecondPointY = Part(z).FirstPointY Then
Part(z).Angle = 90
ElseIf Part(z).SecondPointX > Part(z).Firstpointx And Part(z).SecondPointY > Part(z).FirstPointY Then
Part(z).Angle = 90 - Atn((Part(z).SecondPointY - Part(z).FirstPointY) / (Part(z).SecondPointX - Part(z).Firstpointx)) * 180 / 3.14159265358979
ElseIf Part(z).SecondPointX > Part(z).Firstpointx And Part(z).SecondPointY < Part(z).FirstPointY Then
Part(z).Angle = 90 - Atn((Part(z).SecondPointY - Part(z).FirstPointY) / (Part(z).SecondPointX - Part(z).Firstpointx)) * 180 / 3.14159265358979
ElseIf Part(z).SecondPointX < Part(z).Firstpointx And Part(z).SecondPointY < Part(z).FirstPointY Then
Part(z).Angle = 270 - Atn((Part(z).SecondPointY - Part(z).FirstPointY) / (Part(z).SecondPointX - Part(z).Firstpointx)) * 180 / 3.14159265358979
ElseIf SointX < Part(z).Firstpointx And Part(z).SecondPointY > Part(z).FirstPointY Then
Part(z).Angle = 270 - Atn((Part(z).SecondPointY - FointY) / (Part(z).SecondPointX - Part(z).Firstpointx)) * 180 / 3.14159265358979
End If
Part(z).D = Sqr((GpsX - Part(z).ThirdPointX) ^ 2 + (GpsY - Part(z).ThirdPointY) ^ 2)
End If
Else
Part(z).D = 9998
End If
Debug.Print i, Part(z).D, k1, Part(z).ThirdPointX, Part(z).ThirdPointY, "1111111111111111", Part(z).Angle
If Part(z).D <> 9998 Then
If LastGpsX <> 0 And LastGpsY <> 0 Then
If GpsY = LastGpsY And GpsX <> LastGpsX Then
agl = 90
ElseIf GpsX = LastGpsX Then
agl = 0
Else
If GpsY > LastGpsY And GpsX > LastGpsX Then
agl = 90 - Atn((LastGpsY - GpsY) / (LastGpsX - GpsX)) * 180 / 3.14159265358979
ElseIf GpsY < LastGpsY And GpsX < LastGpsX Then
agl = 270 - Atn((LastGpsY - GpsY) / (LastGpsX - GpsX)) * 180 / 3.14159265358979
ElseIf GpsY < LastGpsY And GpsX > LastGpsX Then
agl = 90 - Atn((LastGpsY - GpsY) / (LastGpsX - GpsX)) * 180 / 3.14159265358979
ElseIf GpsY > LastGpsY And GpsX < LastGpsX Then
agl = 270 - Atn((LastGpsY - GpsY) / (LastGpsX - GpsX)) * 180 / 3.14159265358979
End If
End If
Debug.Print agl, "agl", LastGpsX, LastGpsY, GpsX, GpsY
disagl = Abs(Part(z).Angle - agl)
Debug.Print disagl
If disagl > 90 And disagl < 180 Then
Part(z).DisAngle = 180 - disagl
ElseIf disagl > 180 And disagl < 270 Then
Part(z).DisAngle = disagl - 180
ElseIf disagl > 270 Then
Part(z).DisAngle = 360 - disagl
Else
Part(z).DisAngle = disagl
End If
Debug.Print Part(z).DisAngle, "Part(z).DisAngle"
End If
End If
If Part(z).D <> 9998 Then
If Part(z).D < PMax Then
PMax = Part(z).D
g = z
Else
PMax = PMax
End If
Debug.Print PMax, "PMax"
Part(z).D = PMax
End If
z = z + 1
Next
Debug.Print g, "g"
If g <> 0 Then
Road(i).D = Part(g).D
Road(i).ThirdPointX = Part(g).ThirdPointX
Road(i).ThirdPointY = Part(g).ThirdPointY
Road(i).DisAngle = Part(g).DisAngle
Else
Road(i).D = 9998
Road(i).DisAngle = 360
End If
Debug.Print "i", i, Road(i).D, Road(i).DisAngle
'圆弧路段
ElseIf ft_fin.Parts.Item(1).Count > 9 Then
For k1 = 1 To ft_fin.Parts.Item(1).Count - 1
FpointX = ft_fin.Parts.Item(1).Item(k1).X
FpointY = ft_fin.Parts.Item(1).Item(k1).Y
SpointX = ft_fin.Parts.Item(1).Item(k1 + 1).X
SpointY = ft_fin.Parts.Item(1).Item(k1 + 1).Y
Debug.Print FpointX, FpointY, SpointX, SpointY
If FpointX = SpointX And FpointY <> SpointY Then
TpointX = FpointX
TpointY = GpsY
ElseIf FpointY = SpointY And FpointX <> SpointX Then
TpointX = GpsX
TpointY = FpointY
ElseIf FpointX = SpointX And FpointY = SpointY Then
TpointX = FpointX
TpointY = FpointY
ElseIf FpointX < SpointX Or FpointY < SpointY Then
m1 = (SpointY - FpointY) / (SpointX - FpointX)
m2 = -1 / m1
TpointX = (GpsY - SpointY - m2 * GpsX + m1 * SpointX) / (m1 - m2)
TpointY = m1 * (TpointX - SpointX) + SpointY
ElseIf FpointX > SpointX Or FpointY > SpointY Then
m1 = (SpointY - FpointY) / (SpointX - FpointX)
m2 = -1 / m1
TpointX = (GpsY - FpointY - m2 * GpsX + m1 * FpointX) / (m1 - m2)
TpointY = m1 * (TpointX - FpointX) + FpointY
End If
Debug.Print TpointX, TpointY
Debug.Print ((Form1.Map1.Distance(TpointX, TpointY, FpointX, FpointY) + Form1.Map1.Distance(TpointX, TpointY, SpointX, SpointY)) - Form1.Map1.Distance(FpointX, FpointY, SpointX, SpointY))
If (Form1.Map1.Distance(TpointX, TpointY, FpointX, FpointY) + Form1.Map1.Distance(TpointX, TpointY, SpointX, SpointY)) - Form1.Map1.Distance(FpointX, FpointY, SpointX, SpointY) < small Then
If FpointX = SpointX And FpointY = SpointY Then
Road(i).D = 9998
Else
Road(i).ThirdPointX = TpointX
Road(i).ThirdPointY = TpointY
If SpointX = FpointX Then
Road(i).Angle = 90
ElseIf SpointY = FpointY Then
Road(i).Angle = 0
Else
Road(i).Angle = Atn((SpointY - FpointY) / (SpointX - FpointX)) * 180 / 3.14159265358979
End If
Road(i).D = Sqr((GpsX - Road(i).ThirdPointX) ^ 2 + (GpsY - Road(i).ThirdPointY) ^ 2)
End If
Else: Road(i).D = 9998
End If
Debug.Print i, Road(i).D, k1, Road(i).ThirdPointX, Road(i).ThirdPointY & "1111111111111111"
If Road(i).D <> 9998 Then
If LastGpsX <> 0 And LastGpsY <> 0 Then
If GpsY = LastGpsY And GpsX <> LastGpsX Then
agl = 0
ElseIf GpsX = LastGpsX And GpsY > LastGpsY Then
agl = 90
ElseIf GpsX = LastGpsX And GpsY < LastGpsY Then
agl = -90
Else
agl = Atn((GpsY - LastGpsY) / (GpsX - LastGpsX)) * 180 / 3.14159265358979
End If
If Road(i).Angle * agl < 0 Then
disagl = Abs(Abs(Road(i).Angle) - Abs(agl))
Else
disagl = Abs(Road(i).Angle - agl)
End If
If disagl > 50 Then
Road(i).D = 9998
End If
End If
End If
Debug.Print i, "i", Road(i).Angle, "angle", agl, "agl", disagl, "hahaha"
If Road(i).D < Max Then
Max = Road(i).D
Else
Max = Max
End If
Road(i).D = Max
Next
Debug.Print Max, "max", Road(i).D, "ddddddddd", i, "iiiiiiii", Road(i).Angle, "road(i).angle"
End If
'路段处理过程%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%(就是附值road(i).d过程) 完毕
Dim ddd As Double
Dim ttt As Double
ddd = Form1.Map1.Distance(Road(i).ThirdPointX, Road(i).ThirdPointY, LCarGpsX, LCarGpsY)
ttt = Form1.Map1.Distance(LastGpsX, LastGpsY, GpsX, GpsY)
Debug.Print ddd, "ddd", ttt, "ttt"
If Road(i).D <> 9998 Then
If Road(i).DisAngle < AglMax Then
AglMax = Road(i).DisAngle
If ddd < big Then
big = ddd
j = i
ElseIf ddd > big Then
Debug.Print Abs(ddd - ttt)
If Abs(ddd - ttt) < 0.004 Then
j = i
End If
End If
ElseIf Road(i).DisAngle > AglMax Then
Road(i).D = 9998
End If
End If
i = i + 1
Next
Debug.Print j, "wjwjwjwjwjwjwj"
If j = 9999 Then
MapMatch.X = GpsX
MapMatch.Y = GpsY
Else
Debug.Print Road(j).Name, "road.name"
If Road(j).ThirdPointX <> 0 And Road(j).ThirdPointY <> 0 Then
MapMatch.X = Road(j).ThirdPointX
MapMatch.Y = Road(j).ThirdPointY
Else
MapMatch.X = LCarGpsX
MapMatch.Y = LCarGpsY
End If
End If
Debug.Print MapMatch.X, MapMatch.Y, LCarGpsX, LCarGpsY, "car qqqqqqqqqqqqqqqqqq"
'Debug.Print big, j, CarGpsX, CarGpsY, Road(j).D
End If
End If
'匹配过程———————————————————————————————————————
LastGpsX = GpsX
LastGpsY = GpsY
LCarGpsX = MapMatch.X
LCarGpsY = MapMatch.Y
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -