Angle working for multiple grating SW

This commit is contained in:
Mans 2021-04-15 14:32:31 +02:00
parent 27c344123e
commit 66a8c1d3c1
1 changed files with 175 additions and 123 deletions

View File

@ -9,8 +9,8 @@ Public Class Multiple_Drawing
Dim swApp As SldWorks.SldWorks Dim swApp As SldWorks.SldWorks
swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks.SldWorks) swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks.SldWorks)
Dim Model As ModelDoc2 Dim Model As ModelDoc2
Dim RootPoint(2) As Double Dim RootPoint(2) As Decimal
Dim Normal(2) As Double Dim Normal(2) As Decimal
swApp.UserControl = True swApp.UserControl = True
Dim swSkMgr As SketchManager Dim swSkMgr As SketchManager
@ -114,17 +114,17 @@ Public Class Multiple_Drawing
Dim pointsDT As New DataTable Dim pointsDT As New DataTable
pointsDT.Columns.Add("NAME", GetType(String)) pointsDT.Columns.Add("NAME", GetType(String))
pointsDT.Columns.Add("TYPE", GetType(String)) pointsDT.Columns.Add("TYPE", GetType(String))
pointsDT.Columns.Add("X", GetType(Double)) pointsDT.Columns.Add("X", GetType(Decimal))
pointsDT.Columns.Add("Y", GetType(Double)) pointsDT.Columns.Add("Y", GetType(Decimal))
Dim GAPointsDT As New DataTable Dim GAPointsDT As New DataTable
GAPointsDT.Columns.Add("NAME", GetType(String)) GAPointsDT.Columns.Add("NAME", GetType(String))
GAPointsDT.Columns.Add("X", GetType(Double)) GAPointsDT.Columns.Add("X", GetType(Decimal))
GAPointsDT.Columns.Add("Y", GetType(Double)) GAPointsDT.Columns.Add("Y", GetType(Decimal))
' --- Determine grossArea points ---- ' --- Determine grossArea points ----
Dim pX(3) As Double Dim pX(3) As Decimal
Dim pY(3) As Double Dim pY(3) As Decimal
Dim columnNum As Integer = (i + Grating_Fill.numOfHorizontal) Mod Grating_Fill.numOfHorizontal Dim columnNum As Integer = (i + Grating_Fill.numOfHorizontal) Mod Grating_Fill.numOfHorizontal
If columnNum <> (Grating_Fill.numOfHorizontal - 1) Then If columnNum <> (Grating_Fill.numOfHorizontal - 1) Then
@ -190,8 +190,8 @@ Public Class Multiple_Drawing
recessPointsDT.Columns.Add("NAME", GetType(String)) recessPointsDT.Columns.Add("NAME", GetType(String))
recessPointsDT.Columns.Add("TYPE", GetType(String)) recessPointsDT.Columns.Add("TYPE", GetType(String))
recessPointsDT.Columns.Add("SIDE", GetType(Integer)) recessPointsDT.Columns.Add("SIDE", GetType(Integer))
recessPointsDT.Columns.Add("X", GetType(Double)) recessPointsDT.Columns.Add("X", GetType(Decimal))
recessPointsDT.Columns.Add("Y", GetType(Double)) recessPointsDT.Columns.Add("Y", GetType(Decimal))
For j = 1 To 4 For j = 1 To 4
For Each DR As DataRow In Data.gratingPoints.Rows For Each DR As DataRow In Data.gratingPoints.Rows
@ -257,18 +257,16 @@ Public Class Multiple_Drawing
If temp.Substring(0, 2) = "GA" Then If temp.Substring(0, 2) = "GA" Then
pointsDT.Rows.RemoveAt(index + 2) pointsDT.Rows.RemoveAt(index + 2)
End If End If
Else Else
Dim temp As String = pointsDT.Rows(0)("NAME") Dim temp As String = pointsDT.Rows(0)("NAME")
If temp.Substring(0, 2) = "GA" Then If temp.Substring(0, 2) = "GA" Then
pointsDT.Rows.RemoveAt(0) pointsDT.Rows.RemoveAt(0)
End If End If
End If End If
'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 cornerPoint(1) As Decimal
Dim pointNumGA As Integer = DR("SIDE") + 2 Dim pointNumGA As Integer = DR("SIDE") + 2
If pointNumGA > 4 Then If pointNumGA > 4 Then
pointNumGA -= 4 pointNumGA -= 4
@ -288,21 +286,12 @@ Public Class Multiple_Drawing
Dim index As Integer = Get_RowIndex(pointsDT, DR("SIDE"), DR("X"), DR("Y"), GAPointsDT) Dim index As Integer = Get_RowIndex(pointsDT, DR("SIDE"), DR("X"), DR("Y"), GAPointsDT)
pointsDT.Rows.InsertAt(DR3, index + 1) pointsDT.Rows.InsertAt(DR3, index + 1)
'If pointsDT.Rows.Count > index Then
Dim temp As String = pointsDT.Rows(index)("NAME") Dim temp As String = pointsDT.Rows(index)("NAME")
If temp.Substring(0, 2) = "GA" Then If temp.Substring(0, 2) = "GA" Then
pointsDT.Rows.RemoveAt(index) pointsDT.Rows.RemoveAt(index)
End If End If
'Else Dim cornerPoint(1) As Decimal
' Dim temp As String = pointsDT.Rows(0)("NAME")
' If temp.Substring(0, 2) = "GA" Then
' pointsDT.Rows.RemoveAt(0)
' End If
'End If
Dim cornerPoint(1) As Double
Dim pointNumGA As Integer = DR("SIDE") - 1 Dim pointNumGA As Integer = DR("SIDE") - 1
If pointNumGA < 1 Then If pointNumGA < 1 Then
pointNumGA += 4 pointNumGA += 4
@ -312,17 +301,10 @@ Public Class Multiple_Drawing
cornerPoint(1) = GAPointsDT.Select("NAME = 'GA_" & pointNumGA & "'")(0)("Y") cornerPoint(1) = GAPointsDT.Select("NAME = 'GA_" & pointNumGA & "'")(0)("Y")
Create_SecondAnglePoint(pointsDT, DR, cornerPoint, GAPointsDT, recessPointsDT) Create_SecondAnglePoint(pointsDT, DR, cornerPoint, GAPointsDT, recessPointsDT)
End If End If
End If End If
Next Next
pointsDT.TableName = "Grating " & i & " - C" & columnNum & " R" & rowNum pointsDT.TableName = "Grating " & i & " - C" & columnNum & " R" & rowNum
pointsDS.Tables.Add(pointsDT) pointsDS.Tables.Add(pointsDT)
Next Next
@ -330,11 +312,11 @@ Public Class Multiple_Drawing
Return pointsDS Return pointsDS
End Function End Function
Private Shared Function Get_RowIndex(pDT As DataTable, side As Integer, pX As Double, pY As Double, GApDT As DataTable) Private Shared Function Get_RowIndex(pDT As DataTable, side As Integer, pX As Decimal, pY As Decimal, GApDT As DataTable)
Dim rowName As String = "" Dim rowName As String = ""
Dim newX As Double = pX Dim newX As Decimal = pX
Dim newY As Double = pY Dim newY As Decimal = pY
If side = 1 Then If side = 1 Then
Dim sidePoints = pDT.Select("Y = '" & pY & "'") Dim sidePoints = pDT.Select("Y = '" & pY & "'")
@ -368,14 +350,31 @@ Public Class Multiple_Drawing
Next Next
Else Else
Dim sidePoints = pDT.Select("X = '" & pX & "'") Dim sidePoints = pDT.Select("X = '" & pX & "'")
For Each DR2 As DataRow In sidePoints If sidePoints(0)("NAME") = "GA_1" Then
If DR2("Y") < pY Then Dim pointList As New List(Of DataRow)
rowName = DR2("NAME") For i = 1 To sidePoints.Length - 1
Else pointList.Add(sidePoints(i))
newY = GApDT.Select("NAME = 'GA_4'")(0)("Y") Next
Exit For pointList.Add(sidePoints(0))
End If
Next For Each DR2 As DataRow In pointList
If DR2("Y") < pY Then
rowName = DR2("NAME")
Else
newY = GApDT.Select("NAME = 'GA_4'")(0)("Y")
Exit For
End If
Next
Else
For Each DR2 As DataRow In sidePoints
If DR2("Y") < pY Then
rowName = DR2("NAME")
Else
newY = GApDT.Select("NAME = 'GA_4'")(0)("Y")
Exit For
End If
Next
End If
End If End If
Dim index As Integer = 0 Dim index As Integer = 0
@ -393,14 +392,15 @@ 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(), GApDT As DataTable, rDT As DataTable) Private Shared Sub Create_SecondAnglePoint(pDT As DataTable, rpDR As DataRow, gp As Decimal(), GApDT As DataTable, rDT As DataTable)
Dim p0(1) As Double Dim p0(1) As Decimal
Dim p1(1) As Double Dim p1(1) As Decimal
Dim p2(1) As Double Dim p2(1) As Decimal
Dim newDR As DataRow = pDT.NewRow Dim newDR As DataRow = pDT.NewRow
newDR("TYPE") = "Recess CA" newDR("TYPE") = "Recess CA"
Dim side As Integer = 0
Dim pointName As String = rpDR("NAME") Dim pointName As String = rpDR("NAME")
If pointName.Split("_")(1) = 1 Then If pointName.Split("_")(1) = 1 Then
Dim DR = Data.gratingPoints.Select("NAME = '" & pointName.Split("_")(0) & "_2" & "'") Dim DR = Data.gratingPoints.Select("NAME = '" & pointName.Split("_")(0) & "_2" & "'")
@ -411,48 +411,66 @@ Public Class Multiple_Drawing
p2(0) = DR(0)("X") p2(0) = DR(0)("X")
p2(1) = DR(0)("Y") p2(1) = DR(0)("Y")
If rpDR("SIDE") + 1 > 4 Then
side = rpDR("SIDE") + 1 - 4
Else
side = rpDR("SIDE") + 1
End If
Else Else
Dim DR = Data.gratingPoints.Select("NAME = '" & pointName.Split("_")(0) & "_1" & "'") Dim DR = Data.gratingPoints.Select("NAME = '" & pointName.Split("_")(0) & "_1" & "'")
newDR("NAME") = pointName.Split("_")(0) & "_1" newDR("NAME") = pointName.Split("_")(0) & "_1"
p0(0) = DR(0)("X") p0(0) = rpDR("X")
p0(1) = DR(0)("Y") p0(1) = rpDR("Y")
p2(0) = rpDR("X") p2(0) = DR(0)("X")
p2(1) = rpDR("Y") p2(1) = DR(0)("Y")
If rpDR("SIDE") - 1 < 1 Then
side = rpDR("SIDE") - 1 + 4
Else
side = rpDR("SIDE") - 1
End If
End If End If
For Each rDR As DataRow In rDT.Rows
If rDR("NAME") = newDR("NAME") Then
Exit Sub
End If
Next
If rpDR("SIDE") = 1 OrElse rpDR("SIDE") = 3 Then If rpDR("SIDE") = 1 OrElse rpDR("SIDE") = 3 Then
p1(0) = p2(0) p1(0) = p2(0)
p1(1) = p0(1) p1(1) = p0(1)
If rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("X") = GApDT.Select("NAME = 'GA_2'")(0)("X") OrElse 'If Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") = GApDT.Select("NAME = 'GA_2'")(0)("X") OrElse
rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("X") = GApDT.Select("NAME = 'GA_4'")(0)("X") Then ' Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") = GApDT.Select("NAME = 'GA_4'")(0)("X") Then
If rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") > GApDT.Select("NAME = 'GA_3'")(0)("Y") AndAlso ' If Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") > GApDT.Select("NAME = 'GA_3'")(0)("Y") AndAlso
rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") < GApDT.Select("NAME = 'GA_2'")(0)("Y") Then ' Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") < GApDT.Select("NAME = 'GA_2'")(0)("Y") Then
Exit Sub ' Exit Sub
ElseIf rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") > GApDT.Select("NAME = 'GA_4'")(0)("Y") AndAlso ' ElseIf Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") > GApDT.Select("NAME = 'GA_4'")(0)("Y") AndAlso
rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") < GApDT.Select("NAME = 'GA_1'")(0)("Y") Then ' Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") < GApDT.Select("NAME = 'GA_1'")(0)("Y") Then
Exit Sub ' Exit Sub
End If ' End If
End If 'End If
ElseIf rpDR("SIDE") = 2 OrElse rpDR("SIDE") = 4 Then ElseIf rpDR("SIDE") = 2 OrElse rpDR("SIDE") = 4 Then
p1(0) = p0(0) p1(0) = p0(0)
p1(1) = p2(1) p1(1) = p2(1)
If rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") = GApDT.Select("NAME = 'GA_3'")(0)("Y") OrElse 'If Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") = GApDT.Select("NAME = 'GA_3'")(0)("Y") OrElse
rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") = GApDT.Select("NAME = 'GA_1'")(0)("Y") Then ' Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") = GApDT.Select("NAME = 'GA_1'")(0)("Y") Then
If rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("X") < GApDT.Select("NAME = 'GA_3'")(0)("X") AndAlso ' If Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") < GApDT.Select("NAME = 'GA_3'")(0)("X") AndAlso
rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("X") > GApDT.Select("NAME = 'GA_4'")(0)("X") Then ' Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") > GApDT.Select("NAME = 'GA_4'")(0)("X") Then
Exit Sub ' Exit Sub
ElseIf rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("X") > GApDT.Select("NAME = 'GA_1'")(0)("X") AndAlso ' ElseIf Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") > GApDT.Select("NAME = 'GA_1'")(0)("X") AndAlso
rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("X") < GApDT.Select("NAME = 'GA_2'")(0)("X") Then ' Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") < GApDT.Select("NAME = 'GA_2'")(0)("X") Then
Exit Sub ' Exit Sub
End If ' End If
End If 'End If
End If End If
Dim gpInside As Boolean = Calculate_Triangle_Bool(gp, p0, p1, p2) Dim gpInside As Boolean = Calculate_Triangle_Bool(gp, p0, p1, p2)
@ -460,95 +478,129 @@ Public Class Multiple_Drawing
Dim insertIndex As Integer = 0 Dim insertIndex As Integer = 0
If gpInside = False Then If gpInside = False Then
' If false => new point at side rpDR("SIDE")+1 ' 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 If side = 1 Then
Dim c As Double = GApDT.Select("NAME = 'GA_1'")(0)("Y") - rpDR("Y") Dim x As Decimal = 0
Dim x As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_1'")(0)("X") If pointName.Split("_")(1) = 1 Then
Dim z As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - rpDR("Y") x = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_1'")(0)("X")
Else
x = GApDT.Select("NAME = 'GA_2'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X")
End If
Dim c As Decimal = GApDT.Select("NAME = 'GA_1'")(0)("Y") - rpDR("Y")
Dim z As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - rpDR("Y")
newDR("X") = GApDT.Select("NAME = 'GA_1'")(0)("X") + c * x / z ' Triangle likformighet newDR("X") = GApDT.Select("NAME = 'GA_1'")(0)("X") + c * x / z ' Triangle likformighet
newDR("Y") = GApDT.Select("NAME = 'GA_1'")(0)("Y") newDR("Y") = GApDT.Select("NAME = 'GA_1'")(0)("Y")
ElseIf side = 2 Then ElseIf side = 2 Then
Dim c As Double = GApDT.Select("NAME = 'GA_2'")(0)("X") - rpDR("X") Dim x As Decimal = 0
Dim x As Double = GApDT.Select("NAME = 'GA_2'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") If pointName.Split("_")(1) = 1 Then
Dim z As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - rpDR("X") x = GApDT.Select("NAME = 'GA_2'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y")
Else
x = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_3'")(0)("Y")
End If
Dim c As Decimal = GApDT.Select("NAME = 'GA_2'")(0)("X") - rpDR("X")
Dim z As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - rpDR("X")
newDR("X") = GApDT.Select("NAME = 'GA_2'")(0)("X") newDR("X") = GApDT.Select("NAME = 'GA_2'")(0)("X")
newDR("Y") = GApDT.Select("NAME = 'GA_2'")(0)("Y") - c * x / z ' Triangle likformighet newDR("Y") = GApDT.Select("NAME = 'GA_2'")(0)("Y") - c * x / z ' Triangle likformighet
ElseIf side = 3 Then ElseIf side = 3 Then
Dim c As Double = rpDR("Y") - GApDT.Select("NAME = 'GA_3'")(0)("Y") Dim x As Decimal = 0
Dim x As Double = GApDT.Select("NAME = 'GA_3'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") If pointName.Split("_")(1) = 1 Then
Dim z As Double = rpDR("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") x = GApDT.Select("NAME = 'GA_3'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X")
Else
x = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_4'")(0)("X")
End If
Dim c As Decimal = rpDR("Y") - GApDT.Select("NAME = 'GA_3'")(0)("Y")
Dim z As Decimal = rpDR("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y")
newDR("X") = GApDT.Select("NAME = 'GA_3'")(0)("X") - c * x / z ' Triangle likformighet newDR("X") = GApDT.Select("NAME = 'GA_3'")(0)("X") - c * x / z ' Triangle likformighet
newDR("Y") = GApDT.Select("NAME = 'GA_3'")(0)("Y") newDR("Y") = GApDT.Select("NAME = 'GA_3'")(0)("Y")
Else Else
Dim c As Double = rpDR("X") - GApDT.Select("NAME = 'GA_4'")(0)("X") Dim x As Decimal = 0
Dim x As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_4'")(0)("Y") If pointName.Split("_")(1) = 1 Then
Dim z As Double = rpDR("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") x = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_4'")(0)("Y")
Else
x = GApDT.Select("NAME = 'GA_1'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y")
End If
Dim c As Decimal = rpDR("X") - GApDT.Select("NAME = 'GA_4'")(0)("X")
Dim z As Decimal = rpDR("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X")
newDR("X") = GApDT.Select("NAME = 'GA_4'")(0)("X") newDR("X") = GApDT.Select("NAME = 'GA_4'")(0)("X")
newDR("Y") = GApDT.Select("NAME = 'GA_4'")(0)("Y") + c * x / z ' Triangle likformighet newDR("Y") = GApDT.Select("NAME = 'GA_4'")(0)("Y") + c * x / z ' Triangle likformighet
End If End If
newDR("X") = Math.Round(newDR("X"), 3)
newDR("Y") = Math.Round(newDR("Y"), 3)
insertIndex = Get_RowIndex(pDT, side, newDR("X"), newDR("Y"), GApDT) + 1 insertIndex = Get_RowIndex(pDT, side, newDR("X"), newDR("Y"), GApDT) + 1
Else Else
' If true => remove point gp and new point at side rpDR("SIDE")+2 ' If true => remove point gp and new point at side rpDR("SIDE")+2
Dim side As Integer = 0 Dim temp As String = newDR("NAME")
If rpDR("SIDE") + 2 > 4 Then If temp.Split("_")(1) = 1 Then
side = rpDR("SIDE") + 2 - 4 If side = 1 Then
side = 4
Else
side -= 1
End If
Else Else
side = rpDR("SIDE") + 2 If side = 4 Then
side = 1
Else
side += 1
End If
End If End If
'FIXA If side = 1 Then
'If side = 1 Then Dim x As Decimal = rpDR("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X")
' Dim c As Double = pDT.Select("NAME = 'P1'")(0)("Y") - rpDR("Y") Dim b As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_1'")(0)("Y")
' Dim x As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - pDT.Select("NAME = 'P1'")(0)("X") Dim y As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - rpDR("Y")
' Dim z As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - rpDR("Y") newDR("X") = GApDT.Select("NAME = 'GA_1'")(0)("X") + x * b / y - (GApDT.Select("NAME = 'GA_1'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X")) ' Triangle likformighet
' newDR("X") = pDT.Select("NAME = 'P1'")(0)("X") + c * x / z ' Triangle likformighet newDR("Y") = GApDT.Select("NAME = 'GA_1'")(0)("Y")
' newDR("Y") = pDT.Select("NAME = 'P1'")(0)("Y") ElseIf side = 2 Then
'ElseIf side = 2 Then Dim x As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - rpDR("Y")
' Dim c As Double = pDT.Select("NAME = 'P2'")(0)("X") - rpDR("X") Dim b As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_2'")(0)("X")
' Dim x As Double = pDT.Select("NAME = 'P2'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") Dim y As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - rpDR("X")
' Dim z As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - rpDR("X") newDR("X") = GApDT.Select("NAME = 'GA_2'")(0)("X")
' newDR("X") = pDT.Select("NAME = 'P2'")(0)("X") newDR("Y") = GApDT.Select("NAME = 'GA_2'")(0)("Y") - x * b / y + (Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_2'")(0)("Y")) ' Triangle likformighet
' newDR("Y") = pDT.Select("NAME = 'P2'")(0)("Y") - c * x / z ' Triangle likformighet ElseIf side = 3 Then
'ElseIf side = 3 Then Dim x As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - rpDR("X")
' Dim c As Double = rpDR("Y") - pDT.Select("NAME = 'P3'")(0)("Y") Dim b As Decimal = GApDT.Select("NAME = 'GA_3'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y")
' Dim x As Double = pDT.Select("NAME = 'P3'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") Dim y As Decimal = rpDR("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y")
' Dim z As Double = rpDR("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") newDR("X") = GApDT.Select("NAME = 'GA_3'")(0)("X") - x * b / y + (Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_3'")(0)("X")) ' Triangle likformighet
' newDR("X") = pDT.Select("NAME = 'P3'")(0)("X") - c * x / z ' Triangle likformighet newDR("Y") = GApDT.Select("NAME = 'GA_3'")(0)("Y")
' newDR("Y") = pDT.Select("NAME = 'P3'")(0)("Y") Else
'Else Dim x As Decimal = rpDR("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y")
' Dim c As Double = rpDR("X") - pDT.Select("NAME = 'P4'")(0)("X") Dim b As Decimal = GApDT.Select("NAME = 'GA_4'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X")
' Dim x As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - pDT.Select("NAME = 'P4'")(0)("Y") Dim y As Decimal = rpDR("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X")
' Dim z As Double = rpDR("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") newDR("X") = GApDT.Select("NAME = 'GA_4'")(0)("X")
' newDR("X") = pDT.Select("NAME = 'P4'")(0)("X") newDR("Y") = GApDT.Select("NAME = 'GA_4'")(0)("Y") + x * b / y - (GApDT.Select("NAME = 'GA_4'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y")) ' Triangle likformighet
' newDR("Y") = pDT.Select("NAME = 'P4'")(0)("Y") + c * x / z ' Triangle likformighet End If
'End If
insertIndex = Get_RowIndex(pDT, side, newDR("X"), newDR("Y"), GApDT) insertIndex = Get_RowIndex(pDT, side, newDR("X"), newDR("Y"), GApDT)
pDT.Rows.RemoveAt(insertIndex) If pointName.Split("_")(1) = 1 Then
pDT.Rows.RemoveAt(insertIndex)
Else
If pDT.Rows.Count > insertIndex + 1 Then
pDT.Rows.RemoveAt(insertIndex + 1)
insertIndex += 1
Else
pDT.Rows.RemoveAt(0)
insertIndex = 0
End If
End If
End If End If
pDT.Rows.InsertAt(newDR, insertIndex) pDT.Rows.InsertAt(newDR, insertIndex)
End Sub End Sub
Private Shared Function Calculate_Triangle_Bool(gp As Double(), p0 As Double(), p1 As Double(), p2 As Double()) Private Shared Function Calculate_Triangle_Bool(gp As Decimal(), p0 As Decimal(), p1 As Decimal(), p2 As Decimal())
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 s As Decimal = 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) Dim t As Decimal = 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 If (s < 0 AndAlso t >= 0) OrElse (s >= 0 AndAlso t < 0) Then
Return False Return False
End If 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) Dim area As Decimal = -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 area < 0 Then
If s <= 0 AndAlso s + t >= area Then If s <= 0 AndAlso s + t >= area Then