Sub acaksumber()
Sheets("Sheet1").UsedRange.ClearContents
MAXJARAK = 10000
MAXREPEAT = 10000
salahSensor = 20
radiusSensor = 1000
latensilo = 1
latensihi = 100
errorGPS = WorksheetFunction.RandBetween(-salahSensor, salahSensor) * 1000 / 340
v = 340
x1 = radiusSensor
y1 = 0
x2 = 0
y2 = radiusSensor
x3 = -(radiusSensor)
y3 = 0
x4 = 0
y4 = -(radiusSensor)
Count = 0
Count0 = 0
t1p = 0
t2p = 0
t3p = 0
t4p = 0
For i = 1 To MAXREPEAT
Cells(i, 1) = (-1) ^ Int(Rnd * 10) * Int(MAXJARAK * Rnd)
Cells(i, 2) = (-1) ^ Int(Rnd * 10) * Int(MAXJARAK * Rnd)
If (Cells(i, 1) >= 0) And (Cells(i, 2) >= 0) Then
If (Cells(i, 1) >= Cells(i, 2)) Then
Cells(i, 3) = "A"
Else
Cells(i, 3) = "B"
End If
ElseIf (Cells(i, 1) <= 0) And (Cells(i, 2) >= 0) Then
If (Abs(Cells(i, 1)) >= Cells(i, 2)) Then
Cells(i, 3) = "D"
Else
Cells(i, 3) = "C"
End If
ElseIf (Cells(i, 1) <= 0) And (Cells(i, 2) <= 0) Then
If (Abs(Cells(i, 1)) >= Abs(Cells(i, 2))) Then
Cells(i, 3) = "E"
Else
Cells(i, 3) = "F"
End If
Else
If (Cells(i, 1) >= Abs(Cells(i, 2))) Then
Cells(i, 3) = "H"
Else
Cells(i, 3) = "G"
End If
End If
Next
For i = 1 To MAXREPEAT
d1 = Sqr((Cells(i, 1) - x1) ^ 2 + (Cells(i, 2) - y1) ^ 2)
d2 = Sqr((Cells(i, 1) - x2) ^ 2 + (Cells(i, 2) - y2) ^ 2)
d3 = Sqr((Cells(i, 1) - x3) ^ 2 + (Cells(i, 2) - y3) ^ 2)
d4 = Sqr((Cells(i, 1) - x4) ^ 2 + (Cells(i, 2) - y4) ^ 2)
t1 = d1 / 340
t2 = d2 / 340
t3 = d3 / 340
t4 = d4 / 340
Cells(i, 4) = t1
Cells(i, 5) = t2
Cells(i, 6) = t3
Cells(i, 7) = t4
If latensihi <> 0 Then
t1p = WorksheetFunction.RandBetween(latensilo, latensihi) / 1000
t2p = WorksheetFunction.RandBetween(latensilo, latensihi) / 1000
t3p = WorksheetFunction.RandBetween(latensilo, latensihi) / 1000
t4p = WorksheetFunction.RandBetween(latensilo, latensihi) / 1000
End If
' t1a = t1 + (-1) ^ Int(Rnd * 10) * Int(latensihi * Rnd) / 1000
' t2a = t2 + (-1) ^ Int(Rnd * 10) * Int(latensihi * Rnd) / 1000
' t3a = t3 + (-1) ^ Int(Rnd * 10) * Int(latensihi * Rnd) / 1000
' t4a = t4 + (-1) ^ Int(Rnd * 10) * Int(latensihi * Rnd) / 1000
t1a = t1 + t1p
t2a = t2 + t2p
t3a = t3 + t3p
t4a = t4 + t4p
t12a = t1a - t2a
t13a = t1a - t3a
t14a = t1a - t4a
t23a = t2a - t3a
t24a = t2a - t4a
t34a = t3a - t4a
If Abs(t12a) < 0.00002268 Then t12 = 0
If Abs(t13a) < 0.00002268 Then t13 = 0
If Abs(t14a) < 0.00002268 Then t14 = 0
If Abs(t23a) < 0.00002268 Then t23 = 0
If Abs(t24a) < 0.00002268 Then t24 = 0
If Abs(t34a) < 0.00002268 Then t34 = 0
t12 = t1 - t2
t13 = t1 - t3
t14 = t1 - t4
t23 = t2 - t3
t24 = t2 - t4
t34 = t3 - t4
If Abs(t12) < 0.00002268 Then t12 = 0
If Abs(t13) < 0.00002268 Then t13 = 0
If Abs(t14) < 0.00002268 Then t14 = 0
If Abs(t23) < 0.00002268 Then t23 = 0
If Abs(t24) < 0.00002268 Then t24 = 0
If Abs(t34) < 0.00002268 Then t34 = 0
D12 = Sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2)
D13 = Sqr((x1 - x3) ^ 2 + (y1 - y3) ^ 2)
D14 = Sqr((x1 - x4) ^ 2 + (y1 - y4) ^ 2)
D23 = Sqr((x2 - x3) ^ 2 + (y2 - y3) ^ 2)
D24 = Sqr((x2 - x4) ^ 2 + (y2 - y4) ^ 2)
D34 = Sqr((x3 - x4) ^ 2 + (y3 - y4) ^ 2)
bd12 = t12 * 340
bd13 = t13 * 340
bd14 = t14 * 340
bd23 = t23 * 340
bd24 = t24 * 340
bd34 = t34 * 340
Cells(i, 8) = t12
Cells(i, 9) = t13
Cells(i, 10) = t14
Cells(i, 11) = t23
Cells(i, 12) = t24
Cells(i, 13) = t34
' If (t13 <= 0) And (t24 <= 0) Then
' If (t12 <= 0) Or (t34 >= 0) Then
' Cells(i, 20) = "A"
' Else
' Cells(i, 20) = "B"
' End If
'
' ElseIf (t13 >= 0) And (t24 <= 0) Then
' If (t23 <= 0) Or (t14 <= 0) Then
' Cells(i, 20) = "C"
' Else
' Cells(i, 20) = "D"
' End If
'
' ElseIf (t13 >= 0) And (t24 >= 0) Then
' If (t12 >= 0) Or (t34 <= 0) Then
' Cells(i, 20) = "E"
' Else
' Cells(i, 20) = "F"
' End If
' Else
' If (t23 >= 0) Or (t14 >= 0) Then
' Cells(i, 20) = "G"
' Else
' Cells(i, 20) = "H"
' End If
' End If
Cells(i, 20) = Cells(i, 3)
Cells(i, 14) = t12a
Cells(i, 15) = t13a
Cells(i, 16) = t14a
Cells(i, 17) = t23a
Cells(i, 18) = t24a
Cells(i, 19) = t34a
If (t13a <= 0) And (t24a <= 0) Then
If (t12a <= 0) Or (t34a >= 0) Then
Cells(i, 21) = "A"
Else
Cells(i, 21) = "B"
End If
ElseIf (t13a >= 0) And (t24a <= 0) Then
If (t23a <= 0) Or (t14a <= 0) Then
Cells(i, 21) = "C"
Else
Cells(i, 21) = "D"
End If
ElseIf (t13a >= 0) And (t24a >= 0) Then
If (t12a >= 0) Or (t34a <= 0) Then
Cells(i, 21) = "E"
Else
Cells(i, 21) = "F"
End If
Else
If (t23a >= 0) Or (t14a >= 0) Then
Cells(i, 21) = "G"
Else
Cells(i, 21) = "H"
End If
End If
If Cells(i, 3) = Cells(i, 21) Then
Count0 = Count0 + 1
Else
Count = Count + 1
Cells(i, 22) = 1
End If
Cells(i, 23) = t1p
Cells(i, 24) = t2p
Cells(i, 25) = t3p
Cells(i, 26) = t4p
Cells(i, 27) = ""
Cells(i, 28) = ""
Cells(i, 29) = ""
Cells(i, 30) = ""
Next
Cells(1, 22) = 100 - Count / MAXREPEAT * 100
Cells(2, 22) = Count0 / MAXREPEAT * 100
End Sub
Sheets("Sheet1").UsedRange.ClearContents
MAXJARAK = 10000
MAXREPEAT = 10000
salahSensor = 20
radiusSensor = 1000
latensilo = 1
latensihi = 100
errorGPS = WorksheetFunction.RandBetween(-salahSensor, salahSensor) * 1000 / 340
v = 340
x1 = radiusSensor
y1 = 0
x2 = 0
y2 = radiusSensor
x3 = -(radiusSensor)
y3 = 0
x4 = 0
y4 = -(radiusSensor)
Count = 0
Count0 = 0
t1p = 0
t2p = 0
t3p = 0
t4p = 0
For i = 1 To MAXREPEAT
Cells(i, 1) = (-1) ^ Int(Rnd * 10) * Int(MAXJARAK * Rnd)
Cells(i, 2) = (-1) ^ Int(Rnd * 10) * Int(MAXJARAK * Rnd)
If (Cells(i, 1) >= 0) And (Cells(i, 2) >= 0) Then
If (Cells(i, 1) >= Cells(i, 2)) Then
Cells(i, 3) = "A"
Else
Cells(i, 3) = "B"
End If
ElseIf (Cells(i, 1) <= 0) And (Cells(i, 2) >= 0) Then
If (Abs(Cells(i, 1)) >= Cells(i, 2)) Then
Cells(i, 3) = "D"
Else
Cells(i, 3) = "C"
End If
ElseIf (Cells(i, 1) <= 0) And (Cells(i, 2) <= 0) Then
If (Abs(Cells(i, 1)) >= Abs(Cells(i, 2))) Then
Cells(i, 3) = "E"
Else
Cells(i, 3) = "F"
End If
Else
If (Cells(i, 1) >= Abs(Cells(i, 2))) Then
Cells(i, 3) = "H"
Else
Cells(i, 3) = "G"
End If
End If
Next
For i = 1 To MAXREPEAT
d1 = Sqr((Cells(i, 1) - x1) ^ 2 + (Cells(i, 2) - y1) ^ 2)
d2 = Sqr((Cells(i, 1) - x2) ^ 2 + (Cells(i, 2) - y2) ^ 2)
d3 = Sqr((Cells(i, 1) - x3) ^ 2 + (Cells(i, 2) - y3) ^ 2)
d4 = Sqr((Cells(i, 1) - x4) ^ 2 + (Cells(i, 2) - y4) ^ 2)
t1 = d1 / 340
t2 = d2 / 340
t3 = d3 / 340
t4 = d4 / 340
Cells(i, 4) = t1
Cells(i, 5) = t2
Cells(i, 6) = t3
Cells(i, 7) = t4
If latensihi <> 0 Then
t1p = WorksheetFunction.RandBetween(latensilo, latensihi) / 1000
t2p = WorksheetFunction.RandBetween(latensilo, latensihi) / 1000
t3p = WorksheetFunction.RandBetween(latensilo, latensihi) / 1000
t4p = WorksheetFunction.RandBetween(latensilo, latensihi) / 1000
End If
' t1a = t1 + (-1) ^ Int(Rnd * 10) * Int(latensihi * Rnd) / 1000
' t2a = t2 + (-1) ^ Int(Rnd * 10) * Int(latensihi * Rnd) / 1000
' t3a = t3 + (-1) ^ Int(Rnd * 10) * Int(latensihi * Rnd) / 1000
' t4a = t4 + (-1) ^ Int(Rnd * 10) * Int(latensihi * Rnd) / 1000
t1a = t1 + t1p
t2a = t2 + t2p
t3a = t3 + t3p
t4a = t4 + t4p
t12a = t1a - t2a
t13a = t1a - t3a
t14a = t1a - t4a
t23a = t2a - t3a
t24a = t2a - t4a
t34a = t3a - t4a
If Abs(t12a) < 0.00002268 Then t12 = 0
If Abs(t13a) < 0.00002268 Then t13 = 0
If Abs(t14a) < 0.00002268 Then t14 = 0
If Abs(t23a) < 0.00002268 Then t23 = 0
If Abs(t24a) < 0.00002268 Then t24 = 0
If Abs(t34a) < 0.00002268 Then t34 = 0
t12 = t1 - t2
t13 = t1 - t3
t14 = t1 - t4
t23 = t2 - t3
t24 = t2 - t4
t34 = t3 - t4
If Abs(t12) < 0.00002268 Then t12 = 0
If Abs(t13) < 0.00002268 Then t13 = 0
If Abs(t14) < 0.00002268 Then t14 = 0
If Abs(t23) < 0.00002268 Then t23 = 0
If Abs(t24) < 0.00002268 Then t24 = 0
If Abs(t34) < 0.00002268 Then t34 = 0
D12 = Sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2)
D13 = Sqr((x1 - x3) ^ 2 + (y1 - y3) ^ 2)
D14 = Sqr((x1 - x4) ^ 2 + (y1 - y4) ^ 2)
D23 = Sqr((x2 - x3) ^ 2 + (y2 - y3) ^ 2)
D24 = Sqr((x2 - x4) ^ 2 + (y2 - y4) ^ 2)
D34 = Sqr((x3 - x4) ^ 2 + (y3 - y4) ^ 2)
bd12 = t12 * 340
bd13 = t13 * 340
bd14 = t14 * 340
bd23 = t23 * 340
bd24 = t24 * 340
bd34 = t34 * 340
Cells(i, 8) = t12
Cells(i, 9) = t13
Cells(i, 10) = t14
Cells(i, 11) = t23
Cells(i, 12) = t24
Cells(i, 13) = t34
' If (t13 <= 0) And (t24 <= 0) Then
' If (t12 <= 0) Or (t34 >= 0) Then
' Cells(i, 20) = "A"
' Else
' Cells(i, 20) = "B"
' End If
'
' ElseIf (t13 >= 0) And (t24 <= 0) Then
' If (t23 <= 0) Or (t14 <= 0) Then
' Cells(i, 20) = "C"
' Else
' Cells(i, 20) = "D"
' End If
'
' ElseIf (t13 >= 0) And (t24 >= 0) Then
' If (t12 >= 0) Or (t34 <= 0) Then
' Cells(i, 20) = "E"
' Else
' Cells(i, 20) = "F"
' End If
' Else
' If (t23 >= 0) Or (t14 >= 0) Then
' Cells(i, 20) = "G"
' Else
' Cells(i, 20) = "H"
' End If
' End If
Cells(i, 20) = Cells(i, 3)
Cells(i, 14) = t12a
Cells(i, 15) = t13a
Cells(i, 16) = t14a
Cells(i, 17) = t23a
Cells(i, 18) = t24a
Cells(i, 19) = t34a
If (t13a <= 0) And (t24a <= 0) Then
If (t12a <= 0) Or (t34a >= 0) Then
Cells(i, 21) = "A"
Else
Cells(i, 21) = "B"
End If
ElseIf (t13a >= 0) And (t24a <= 0) Then
If (t23a <= 0) Or (t14a <= 0) Then
Cells(i, 21) = "C"
Else
Cells(i, 21) = "D"
End If
ElseIf (t13a >= 0) And (t24a >= 0) Then
If (t12a >= 0) Or (t34a <= 0) Then
Cells(i, 21) = "E"
Else
Cells(i, 21) = "F"
End If
Else
If (t23a >= 0) Or (t14a >= 0) Then
Cells(i, 21) = "G"
Else
Cells(i, 21) = "H"
End If
End If
If Cells(i, 3) = Cells(i, 21) Then
Count0 = Count0 + 1
Else
Count = Count + 1
Cells(i, 22) = 1
End If
Cells(i, 23) = t1p
Cells(i, 24) = t2p
Cells(i, 25) = t3p
Cells(i, 26) = t4p
Cells(i, 27) = ""
Cells(i, 28) = ""
Cells(i, 29) = ""
Cells(i, 30) = ""
Next
Cells(1, 22) = 100 - Count / MAXREPEAT * 100
Cells(2, 22) = Count0 / MAXREPEAT * 100
End Sub