This commit is contained in:
Anton 2021-04-14 15:43:03 +02:00
parent b22c45ca34
commit c29b4a223a
1 changed files with 170 additions and 14 deletions

View File

@ -238,9 +238,8 @@ Public Class Multiple_Drawing
DR3("TYPE") = "Recess CA" DR3("TYPE") = "Recess CA"
DR3("X") = DR("X") DR3("X") = DR("X")
DR3("Y") = DR("Y") DR3("Y") = DR("Y")
Dim index As Integer = Get_RowIndex(pointsDT, DR)
Dim index As Integer = Get_RowIndex(pointsDT, DR("SIDE"), DR("X"), DR("Y"))
pointsDT.Rows.InsertAt(DR3, index + 1) pointsDT.Rows.InsertAt(DR3, index + 1)
Try Try
@ -250,6 +249,16 @@ Public Class Multiple_Drawing
End Try End Try
'Check if remove next point aswell (If angle crosses more than one grating) 'Check if remove next point aswell (If angle crosses more than one grating)
Dim cornerPoint(1) As Double
Dim pointNumGA As Integer = DR("SIDE") + 2
If pointNumGA > 4 Then
pointNumGA -= 4
End If
cornerPoint(0) = pointsDT.Select("NAME = 'GA_" & pointNumGA & "'")(0)("X")
cornerPoint(1) = pointsDT.Select("NAME = 'GA_" & pointNumGA & "'")(0)("Y")
Create_SecondAnglePoint(pointsDT, DR, cornerPoint)
Else Else
End If End If
@ -268,40 +277,40 @@ Public Class Multiple_Drawing
Return pointsDS Return pointsDS
End Function End Function
Private Shared Function Get_RowIndex(pDT As DataTable, rpDR As DataRow) Private Shared Function Get_RowIndex(pDT As DataTable, side As Integer, pX As Double, pY As Double)
Dim rowName As String = "" Dim rowName As String = ""
If rpDR("SIDE") = 1 Then If side = 1 Then
Dim sidePoints = pDT.Select("Y = '" & rpDR("Y") & "'") Dim sidePoints = pDT.Select("Y = '" & pY & "'")
For Each DR2 As DataRow In sidePoints For Each DR2 As DataRow In sidePoints
If DR2("X") < rpDR("X") Then If DR2("X") < pX Then
rowName = DR2("NAME") rowName = DR2("NAME")
Else Else
Exit For Exit For
End If End If
Next Next
ElseIf rpDR("SIDE") = 2 Then ElseIf side = 2 Then
Dim sidePoints = pDT.Select("X = '" & rpDR("X") & "'") Dim sidePoints = pDT.Select("X = '" & pX & "'")
For Each DR2 As DataRow In sidePoints For Each DR2 As DataRow In sidePoints
If DR2("Y") > rpDR("Y") Then If DR2("Y") > pY Then
rowName = DR2("NAME") rowName = DR2("NAME")
Else Else
Exit For Exit For
End If End If
Next Next
ElseIf rpDR("SIDE") = 3 Then ElseIf side = 3 Then
Dim sidePoints = pDT.Select("Y = '" & rpDR("Y") & "'") Dim sidePoints = pDT.Select("Y = '" & pY & "'")
For Each DR2 As DataRow In sidePoints For Each DR2 As DataRow In sidePoints
If DR2("X") > rpDR("X") Then If DR2("X") > pX Then
rowName = DR2("NAME") rowName = DR2("NAME")
Else Else
Exit For Exit For
End If End If
Next Next
Else Else
Dim sidePoints = pDT.Select("X = '" & rpDR("X") & "'") Dim sidePoints = pDT.Select("X = '" & pX & "'")
For Each DR2 As DataRow In sidePoints For Each DR2 As DataRow In sidePoints
If DR2("Y") < rpDR("Y") Then If DR2("Y") < pY Then
rowName = DR2("NAME") rowName = DR2("NAME")
Else Else
Exit For Exit For
@ -319,4 +328,151 @@ Public Class Multiple_Drawing
Return index Return index
End Function End Function
Private Shared Sub Create_SecondAnglePoint(pDT As DataTable, rpDR As DataRow, gp As Double())
Dim p0(1) As Double
Dim p1(1) As Double
Dim p2(1) As Double
Dim newDR As DataRow = pDT.NewRow
newDR("TYPE") = "Recess CA"
Dim pointName As String = rpDR("NAME")
If pointName.Split("_")(1) = 1 Then
Dim DR = Data.gratingPoints.Select("NAME = '" & pointName.Split("_")(0) & "_2" & "'")
newDR("NAME") = pointName.Split("_")(0) & "_2"
p0(0) = rpDR("X")
p0(1) = rpDR("Y")
p2(0) = DR(0)("X")
p2(1) = DR(0)("Y")
Else
Dim DR = Data.gratingPoints.Select("NAME = '" & pointName.Split("_")(0) & "_1" & "'")
newDR("NAME") = pointName.Split("_")(0) & "_1"
p0(0) = DR(0)("X")
p0(1) = DR(0)("Y")
p2(0) = rpDR("X")
p2(1) = rpDR("Y")
End If
If rpDR("SIDE") = 1 OrElse rpDR("SIDE") = 3 Then
p1(0) = p2(0)
p1(1) = p0(1)
ElseIf rpDR("SIDE") = 2 OrElse rpDR("SIDE") = 4 Then
p1(0) = p0(0)
p1(1) = p2(1)
End If
Dim gpInside As Boolean = Calculate_Triangle_Bool(gp, p0, p1, p2)
Dim insertIndex As Integer = 0
If gpInside = False Then
' If false => new point at side rpDR("SIDE")+1
Dim side As Integer = 0
If rpDR("SIDE") + 1 > 4 Then
side = rpDR("SIDE") + 1 - 4
Else
side = rpDR("SIDE") + 1
End If
' FIXA: GA punkten tas bort innan vi behöver den här
If side = 1 Then
Dim c As Double = pDT.Select("NAME = 'GA_1'")(0)("Y") - rpDR("Y")
Dim x As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - pDT.Select("NAME = 'GA_1'")(0)("X")
Dim z As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - rpDR("Y")
newDR("X") = pDT.Select("NAME = 'GA_1'")(0)("X") + c * x / z ' Triangle likformighet
newDR("Y") = pDT.Select("NAME = 'GA_1'")(0)("Y")
ElseIf side = 2 Then
Dim c As Double = pDT.Select("NAME = 'GA_2'")(0)("X") - rpDR("X")
Dim x As Double = pDT.Select("NAME = 'GA_2'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y")
Dim z As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - rpDR("X")
newDR("X") = pDT.Select("NAME = 'GA_2'")(0)("X")
newDR("Y") = pDT.Select("NAME = 'GA_2'")(0)("Y") - c * x / z ' Triangle likformighet
ElseIf side = 3 Then
Dim c As Double = rpDR("Y") - pDT.Select("NAME = 'GA_3'")(0)("Y")
Dim x As Double = pDT.Select("NAME = 'GA_3'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X")
Dim z As Double = rpDR("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y")
newDR("X") = pDT.Select("NAME = 'GA_3'")(0)("X") - c * x / z ' Triangle likformighet
newDR("Y") = pDT.Select("NAME = 'GA_3'")(0)("Y")
Else
Dim c As Double = rpDR("X") - pDT.Select("NAME = 'GA_4'")(0)("X")
Dim x As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - pDT.Select("NAME = 'GA_4'")(0)("Y")
Dim z As Double = rpDR("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X")
newDR("X") = pDT.Select("NAME = 'GA_4'")(0)("X")
newDR("Y") = pDT.Select("NAME = 'GA_4'")(0)("Y") + c * x / z ' Triangle likformighet
End If
insertIndex = Get_RowIndex(pDT, side, newDR("X"), newDR("Y")) + 1
Else
' If true => remove point gp and new point at side rpDR("SIDE")+2
Dim side As Integer = 0
If rpDR("SIDE") + 2 > 4 Then
side = rpDR("SIDE") + 2 - 4
Else
side = rpDR("SIDE") + 2
End If
'FIXA
'If side = 1 Then
' Dim c As Double = pDT.Select("NAME = 'P1'")(0)("Y") - rpDR("Y")
' Dim x As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - pDT.Select("NAME = 'P1'")(0)("X")
' Dim z As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - rpDR("Y")
' newDR("X") = pDT.Select("NAME = 'P1'")(0)("X") + c * x / z ' Triangle likformighet
' newDR("Y") = pDT.Select("NAME = 'P1'")(0)("Y")
'ElseIf side = 2 Then
' Dim c As Double = pDT.Select("NAME = 'P2'")(0)("X") - rpDR("X")
' Dim x As Double = pDT.Select("NAME = 'P2'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y")
' Dim z As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - rpDR("X")
' newDR("X") = pDT.Select("NAME = 'P2'")(0)("X")
' newDR("Y") = pDT.Select("NAME = 'P2'")(0)("Y") - c * x / z ' Triangle likformighet
'ElseIf side = 3 Then
' Dim c As Double = rpDR("Y") - pDT.Select("NAME = 'P3'")(0)("Y")
' Dim x As Double = pDT.Select("NAME = 'P3'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X")
' Dim z As Double = rpDR("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y")
' newDR("X") = pDT.Select("NAME = 'P3'")(0)("X") - c * x / z ' Triangle likformighet
' newDR("Y") = pDT.Select("NAME = 'P3'")(0)("Y")
'Else
' Dim c As Double = rpDR("X") - pDT.Select("NAME = 'P4'")(0)("X")
' Dim x As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - pDT.Select("NAME = 'P4'")(0)("Y")
' Dim z As Double = rpDR("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X")
' newDR("X") = pDT.Select("NAME = 'P4'")(0)("X")
' newDR("Y") = pDT.Select("NAME = 'P4'")(0)("Y") + c * x / z ' Triangle likformighet
'End If
insertIndex = Get_RowIndex(pDT, side, newDR("X"), newDR("Y"))
pDT.Rows.RemoveAt(insertIndex)
End If
pDT.Rows.InsertAt(newDR, insertIndex)
End Sub
Private Shared Function Calculate_Triangle_Bool(gp As Double(), p0 As Double(), p1 As Double(), p2 As Double())
Dim s As Double = p0(1) * p2(0) - p0(0) * p2(1) + (p2(1) - p0(1)) * gp(0) + (p0(0) - p2(0)) * gp(1)
Dim t As Double = p0(0) * p1(1) - p0(1) * p1(0) + (p0(1) - p1(1)) * gp(0) + (p1(0) - p0(0)) * gp(1)
If (s < 0 AndAlso t >= 0) OrElse (s >= 0 AndAlso t < 0) Then
Return False
End If
Dim area As Double = -p1(1) * p2(0) + p0(1) * (p2(0) - p1(0)) + p0(0) * (p1(1) - p2(1)) + p1(0) * p2(1)
If area < 0 Then
If s <= 0 AndAlso s + t >= area Then
Return True
Else
Return False
End If
Else
If s >= 0 AndAlso s + t <= area Then
Return True
Else
Return False
End If
End If
End Function
End Class End Class