Please find below my 0.01 cent for this discussion. That is the code I use for inlineing in my applications. It is wirtten in visual basic net. I am sure there is a more elegant way so solve but this is mine.
The sub Inline and Reversewinding are what you need. I hope this is not too complicated to understand. For me each line is an object and both sub are methods of the line object.
The sub Inline and Reversewinding are what you need. I hope this is not too complicated to understand. For me each line is an object and both sub are methods of the line object.
Code:
''' <summary>
''' Manipulates the current matrix values according the values from the given Originalline
''' </summary>
''' <param name="objOriginalLine">Line that calls this subpart</param>
''' <param name="reverse">Does nothing so far</param>
''' <remarks></remarks>
Public Sub Inline(ByVal objOriginalLine As cls_LDraw_Line, Optional ByVal reverse As Boolean = False)
'Originalline is the line that should be further extracted.
If objOriginalLine.LineType <> LDraw_DatLineType.Subpart Then Exit Sub
Select Case Me.LineType
Case LDraw_DatLineType.Subpart
Dim tmpDatLinePoint As New cls_LDraw_Point
Dim tmpDatMatrix As New cls_LDraw_Matrix '3x3
tmpDatLinePoint.X = varDatLinePoint1.X
tmpDatLinePoint.Y = varDatLinePoint1.Y
tmpDatLinePoint.Z = varDatLinePoint1.Z
tmpDatMatrix.TransX.X = varDatMatrix.TransX.X
tmpDatMatrix.TransX.Y = varDatMatrix.TransX.Y
tmpDatMatrix.TransX.Z = varDatMatrix.TransX.Z
tmpDatMatrix.TransY.X = varDatMatrix.TransY.X
tmpDatMatrix.TransY.Y = varDatMatrix.TransY.Y
tmpDatMatrix.TransY.Z = varDatMatrix.TransY.Z
tmpDatMatrix.TransZ.X = varDatMatrix.TransZ.X
tmpDatMatrix.TransZ.Y = varDatMatrix.TransZ.Y
tmpDatMatrix.TransZ.Z = varDatMatrix.TransZ.Z
varDatLinePoint1.X = _
tmpDatLinePoint.X * objOriginalLine.TransformMatrix.TransX.X + _
tmpDatLinePoint.Y * objOriginalLine.TransformMatrix.TransX.Y + _
tmpDatLinePoint.Z * objOriginalLine.TransformMatrix.TransX.Z + _
1 * objOriginalLine.Coordinate.X
varDatLinePoint1.Y = _
tmpDatLinePoint.X * objOriginalLine.TransformMatrix.TransY.X + _
tmpDatLinePoint.Y * objOriginalLine.TransformMatrix.TransY.Y + _
tmpDatLinePoint.Z * objOriginalLine.TransformMatrix.TransY.Z + _
1 * objOriginalLine.Coordinate.Y
varDatLinePoint1.Z = _
tmpDatLinePoint.X * objOriginalLine.TransformMatrix.TransZ.X + _
tmpDatLinePoint.Y * objOriginalLine.TransformMatrix.TransZ.Y + _
tmpDatLinePoint.Z * objOriginalLine.TransformMatrix.TransZ.Z + _
1 * objOriginalLine.Coordinate.Z
varDatMatrix.TransX.X = _
tmpDatMatrix.TransX.X * objOriginalLine.TransformMatrix.TransX.X + _
tmpDatMatrix.TransY.X * objOriginalLine.TransformMatrix.TransX.Y + _
tmpDatMatrix.TransZ.X * objOriginalLine.TransformMatrix.TransX.Z + _
0 * objOriginalLine.Coordinate.X
'ok
varDatMatrix.TransX.Y = _
tmpDatMatrix.TransX.Y * objOriginalLine.TransformMatrix.TransX.X + _
tmpDatMatrix.TransY.Y * objOriginalLine.TransformMatrix.TransX.Y + _
tmpDatMatrix.TransZ.Y * objOriginalLine.TransformMatrix.TransX.Z + _
0 * objOriginalLine.Coordinate.X
'ok
varDatMatrix.TransX.Z = _
tmpDatMatrix.TransX.Z * objOriginalLine.TransformMatrix.TransX.X + _
tmpDatMatrix.TransY.Z * objOriginalLine.TransformMatrix.TransX.Y + _
tmpDatMatrix.TransZ.Z * objOriginalLine.TransformMatrix.TransX.Z + _
0 * objOriginalLine.Coordinate.X
'ok
varDatLinePoint2 = varDatMatrix.TransX
varDatMatrix.TransY.X = _
tmpDatMatrix.TransX.X * objOriginalLine.TransformMatrix.TransY.X + _
tmpDatMatrix.TransY.X * objOriginalLine.TransformMatrix.TransY.Y + _
tmpDatMatrix.TransZ.X * objOriginalLine.TransformMatrix.TransY.Z + _
0 * objOriginalLine.Coordinate.Y
'ok
varDatMatrix.TransY.Y = _
tmpDatMatrix.TransX.Y * objOriginalLine.TransformMatrix.TransY.X + _
tmpDatMatrix.TransY.Y * objOriginalLine.TransformMatrix.TransY.Y + _
tmpDatMatrix.TransZ.Y * objOriginalLine.TransformMatrix.TransY.Z + _
0 * objOriginalLine.Coordinate.Y
'ok
varDatMatrix.TransY.Z = _
tmpDatMatrix.TransX.Z * objOriginalLine.TransformMatrix.TransY.X + _
tmpDatMatrix.TransY.Z * objOriginalLine.TransformMatrix.TransY.Y + _
tmpDatMatrix.TransZ.Z * objOriginalLine.TransformMatrix.TransY.Z + _
0 * objOriginalLine.Coordinate.Y
'ok
varDatLinePoint3 = varDatMatrix.TransY
varDatMatrix.TransZ.X = _
tmpDatMatrix.TransX.X * objOriginalLine.TransformMatrix.TransZ.X + _
tmpDatMatrix.TransY.X * objOriginalLine.TransformMatrix.TransZ.Y + _
tmpDatMatrix.TransZ.X * objOriginalLine.TransformMatrix.TransZ.Z + _
0 * objOriginalLine.Coordinate.Z
'ok
varDatMatrix.TransZ.Y = _
tmpDatMatrix.TransX.Y * objOriginalLine.TransformMatrix.TransZ.X + _
tmpDatMatrix.TransY.Y * objOriginalLine.TransformMatrix.TransZ.Y + _
tmpDatMatrix.TransZ.Y * objOriginalLine.TransformMatrix.TransZ.Z + _
0 * objOriginalLine.Coordinate.Z
'ok
varDatMatrix.TransZ.Z = _
tmpDatMatrix.TransX.Z * objOriginalLine.TransformMatrix.TransZ.X + _
tmpDatMatrix.TransY.Z * objOriginalLine.TransformMatrix.TransZ.Y + _
tmpDatMatrix.TransZ.Z * objOriginalLine.TransformMatrix.TransZ.Z + _
0 * objOriginalLine.Coordinate.Z
'ok
varDatLinePoint4 = varDatMatrix.TransZ
If varDatLineColor = "16" Then
varDatLineColor = objOriginalLine.LineColor
End If
Case LDraw_DatLineType.Line
'für linetype2
Dim x1, x2, y1, y2, z1, z2 As Double
'Die Werte für X sind ok aber nicht y und z, da bereits x verändert wurde.:-(
x1 = varDatLinePoint1.X
x2 = varDatLinePoint2.X
y1 = varDatLinePoint1.Y
y2 = varDatLinePoint2.Y
z1 = varDatLinePoint1.Z
z2 = varDatLinePoint2.Z
varDatLinePoint1.X = _
x1 * objOriginalLine.TransformMatrix.TransX.X + _
y1 * objOriginalLine.TransformMatrix.TransX.Y + _
z1 * objOriginalLine.TransformMatrix.TransX.Z + _
objOriginalLine.Coordinate.X
varDatLinePoint1.Y = _
x1 * objOriginalLine.TransformMatrix.TransY.X + _
y1 * objOriginalLine.TransformMatrix.TransY.Y + _
z1 * objOriginalLine.TransformMatrix.TransY.Z + _
objOriginalLine.Coordinate.Y
varDatLinePoint1.Z = _
x1 * objOriginalLine.TransformMatrix.TransZ.X + _
y1 * objOriginalLine.TransformMatrix.TransZ.Y + _
z1 * objOriginalLine.TransformMatrix.TransZ.Z + _
objOriginalLine.Coordinate.Z
varDatLinePoint2.X = _
x2 * objOriginalLine.TransformMatrix.TransX.X + _
y2 * objOriginalLine.TransformMatrix.TransX.Y + _
z2 * objOriginalLine.TransformMatrix.TransX.Z + _
objOriginalLine.Coordinate.X
varDatLinePoint2.Y = _
x2 * objOriginalLine.TransformMatrix.TransY.X + _
y2 * objOriginalLine.TransformMatrix.TransY.Y + _
z2 * objOriginalLine.TransformMatrix.TransY.Z + _
objOriginalLine.Coordinate.Y
varDatLinePoint2.Z = _
x2 * objOriginalLine.TransformMatrix.TransZ.X + _
y2 * objOriginalLine.TransformMatrix.TransZ.Y + _
z2 * objOriginalLine.TransformMatrix.TransZ.Z + _
objOriginalLine.Coordinate.Z
If varDatLineColor = "16" Then
varDatLineColor = objOriginalLine.LineColor
End If
Case LDraw_DatLineType.Triangle
'für linetype3
Dim x1, x2, x3, y1, y2, y3, z1, z2, z3 As Double
x1 = varDatLinePoint1.X
x2 = varDatLinePoint2.X
x3 = varDatLinePoint3.X
y1 = varDatLinePoint1.Y
y2 = varDatLinePoint2.Y
y3 = varDatLinePoint3.Y
z1 = varDatLinePoint1.Z
z2 = varDatLinePoint2.Z
z3 = varDatLinePoint3.Z
varDatLinePoint1.X = x1 * objOriginalLine.TransformMatrix.TransX.X + _
y1 * objOriginalLine.TransformMatrix.TransX.Y + _
z1 * objOriginalLine.TransformMatrix.TransX.Z + _
objOriginalLine.Coordinate.X
varDatLinePoint1.Y = x1 * objOriginalLine.TransformMatrix.TransY.X + _
y1 * objOriginalLine.TransformMatrix.TransY.Y + _
z1 * objOriginalLine.TransformMatrix.TransY.Z + _
objOriginalLine.Coordinate.Y
varDatLinePoint1.Z = x1 * objOriginalLine.TransformMatrix.TransZ.X + _
y1 * objOriginalLine.TransformMatrix.TransZ.Y + _
z1 * objOriginalLine.TransformMatrix.TransZ.Z + _
objOriginalLine.Coordinate.Z
varDatLinePoint2.X = x2 * objOriginalLine.TransformMatrix.TransX.X + _
y2 * objOriginalLine.TransformMatrix.TransX.Y + _
z2 * objOriginalLine.TransformMatrix.TransX.Z + _
objOriginalLine.Coordinate.X
varDatLinePoint2.Y = x2 * objOriginalLine.TransformMatrix.TransY.X + _
y2 * objOriginalLine.TransformMatrix.TransY.Y + _
z2 * objOriginalLine.TransformMatrix.TransY.Z + _
objOriginalLine.Coordinate.Y
varDatLinePoint2.Z = x2 * objOriginalLine.TransformMatrix.TransZ.X + _
y2 * objOriginalLine.TransformMatrix.TransZ.Y + _
z2 * objOriginalLine.TransformMatrix.TransZ.Z + _
objOriginalLine.Coordinate.Z
varDatLinePoint3.X = x3 * objOriginalLine.TransformMatrix.TransX.X + _
y3 * objOriginalLine.TransformMatrix.TransX.Y + _
z3 * objOriginalLine.TransformMatrix.TransX.Z + _
objOriginalLine.Coordinate.X
varDatLinePoint3.Y = x3 * objOriginalLine.TransformMatrix.TransY.X + _
y3 * objOriginalLine.TransformMatrix.TransY.Y + _
z3 * objOriginalLine.TransformMatrix.TransY.Z + _
objOriginalLine.Coordinate.Y
varDatLinePoint3.Z = x3 * objOriginalLine.TransformMatrix.TransZ.X + _
y3 * objOriginalLine.TransformMatrix.TransZ.Y + _
z3 * objOriginalLine.TransformMatrix.TransZ.Z + _
objOriginalLine.Coordinate.Z
If varDatLineColor = "16" Then
varDatLineColor = objOriginalLine.LineColor
End If
If reverse Then
Me.ReverseWinding()
End If
Case LDraw_DatLineType.Quad
Dim x1, x2, x3, x4, y1, y2, y3, y4 As Double
x1 = varDatLinePoint1.X
x2 = varDatLinePoint2.X
x3 = varDatLinePoint3.X
x4 = varDatLinePoint4.X
y1 = varDatLinePoint1.Y
y2 = varDatLinePoint2.Y
y3 = varDatLinePoint3.Y
y4 = varDatLinePoint4.Y
varDatLinePoint1.X = varDatLinePoint1.X * objOriginalLine.TransformMatrix.TransX.X + _
varDatLinePoint1.Y * objOriginalLine.TransformMatrix.TransX.Y + _
varDatLinePoint1.Z * objOriginalLine.TransformMatrix.TransX.Z + _
objOriginalLine.Coordinate.X
varDatLinePoint1.Y = x1 * objOriginalLine.TransformMatrix.TransY.X + _
varDatLinePoint1.Y * objOriginalLine.TransformMatrix.TransY.Y + _
varDatLinePoint1.Z * objOriginalLine.TransformMatrix.TransY.Z + _
objOriginalLine.Coordinate.Y
varDatLinePoint1.Z = x1 * objOriginalLine.TransformMatrix.TransZ.X + _
y1 * objOriginalLine.TransformMatrix.TransZ.Y + _
varDatLinePoint1.Z * objOriginalLine.TransformMatrix.TransZ.Z + _
objOriginalLine.Coordinate.Z
varDatLinePoint2.X = varDatLinePoint2.X * objOriginalLine.TransformMatrix.TransX.X + _
varDatLinePoint2.Y * objOriginalLine.TransformMatrix.TransX.Y + _
varDatLinePoint2.Z * objOriginalLine.TransformMatrix.TransX.Z + _
objOriginalLine.Coordinate.X
varDatLinePoint2.Y = x2 * objOriginalLine.TransformMatrix.TransY.X + _
varDatLinePoint2.Y * objOriginalLine.TransformMatrix.TransY.Y + _
varDatLinePoint2.Z * objOriginalLine.TransformMatrix.TransY.Z + _
objOriginalLine.Coordinate.Y
varDatLinePoint2.Z = x2 * objOriginalLine.TransformMatrix.TransZ.X + _
y2 * objOriginalLine.TransformMatrix.TransZ.Y + _
varDatLinePoint2.Z * objOriginalLine.TransformMatrix.TransZ.Z + _
objOriginalLine.Coordinate.Z
varDatLinePoint3.X = varDatLinePoint3.X * objOriginalLine.TransformMatrix.TransX.X + _
varDatLinePoint3.Y * objOriginalLine.TransformMatrix.TransX.Y + _
varDatLinePoint3.Z * objOriginalLine.TransformMatrix.TransX.Z + _
objOriginalLine.Coordinate.X
varDatLinePoint3.Y = x3 * objOriginalLine.TransformMatrix.TransY.X + _
varDatLinePoint3.Y * objOriginalLine.TransformMatrix.TransY.Y + _
varDatLinePoint3.Z * objOriginalLine.TransformMatrix.TransY.Z + _
objOriginalLine.Coordinate.Y
varDatLinePoint3.Z = x3 * objOriginalLine.TransformMatrix.TransZ.X + _
y3 * objOriginalLine.TransformMatrix.TransZ.Y + _
varDatLinePoint3.Z * objOriginalLine.TransformMatrix.TransZ.Z + _
objOriginalLine.Coordinate.Z
varDatLinePoint4.X = varDatLinePoint4.X * objOriginalLine.TransformMatrix.TransX.X + _
varDatLinePoint4.Y * objOriginalLine.TransformMatrix.TransX.Y + _
varDatLinePoint4.Z * objOriginalLine.TransformMatrix.TransX.Z + _
objOriginalLine.Coordinate.X
varDatLinePoint4.Y = x4 * objOriginalLine.TransformMatrix.TransY.X + _
varDatLinePoint4.Y * objOriginalLine.TransformMatrix.TransY.Y + _
varDatLinePoint4.Z * objOriginalLine.TransformMatrix.TransY.Z + _
objOriginalLine.Coordinate.Y
varDatLinePoint4.Z = x4 * objOriginalLine.TransformMatrix.TransZ.X + _
y4 * objOriginalLine.TransformMatrix.TransZ.Y + _
varDatLinePoint4.Z * objOriginalLine.TransformMatrix.TransZ.Z + _
objOriginalLine.Coordinate.Z
If varDatLineColor = "16" Then
varDatLineColor = objOriginalLine.LineColor
End If
If reverse Then
Me.ReverseWinding()
End If
Case LDraw_DatLineType.OptLine
Dim x1, x2, x3, x4, y1, y2, y3, y4 As Double
x1 = varDatLinePoint1.X
x2 = varDatLinePoint2.X
x3 = varDatLinePoint3.X
x4 = varDatLinePoint4.X
y1 = varDatLinePoint1.Y
y2 = varDatLinePoint2.Y
y3 = varDatLinePoint3.Y
y4 = varDatLinePoint4.Y
varDatLinePoint1.X = x1 * objOriginalLine.TransformMatrix.TransX.X + _
y1 * objOriginalLine.TransformMatrix.TransX.Y + _
varDatLinePoint1.Z * objOriginalLine.TransformMatrix.TransX.Z + _
objOriginalLine.Coordinate.X
varDatLinePoint1.Y = x1 * objOriginalLine.TransformMatrix.TransY.X + _
y1 * objOriginalLine.TransformMatrix.TransY.Y + _
varDatLinePoint1.Z * objOriginalLine.TransformMatrix.TransY.Z + _
objOriginalLine.Coordinate.Y
varDatLinePoint1.Z = x1 * objOriginalLine.TransformMatrix.TransZ.X + _
y1 * objOriginalLine.TransformMatrix.TransZ.Y + _
varDatLinePoint1.Z * objOriginalLine.TransformMatrix.TransZ.Z + _
objOriginalLine.Coordinate.Z
varDatLinePoint2.X = varDatLinePoint2.X * objOriginalLine.TransformMatrix.TransX.X + _
y2 * objOriginalLine.TransformMatrix.TransX.Y + _
varDatLinePoint2.Z * objOriginalLine.TransformMatrix.TransX.Z + _
objOriginalLine.Coordinate.X
varDatLinePoint2.Y = x2 * objOriginalLine.TransformMatrix.TransY.X + _
y2 * objOriginalLine.TransformMatrix.TransY.Y + _
varDatLinePoint2.Z * objOriginalLine.TransformMatrix.TransY.Z + _
objOriginalLine.Coordinate.Y
varDatLinePoint2.Z = x2 * objOriginalLine.TransformMatrix.TransZ.X + _
y2 * objOriginalLine.TransformMatrix.TransZ.Y + _
varDatLinePoint2.Z * objOriginalLine.TransformMatrix.TransZ.Z + _
objOriginalLine.Coordinate.Z
varDatLinePoint3.X = varDatLinePoint3.X * objOriginalLine.TransformMatrix.TransX.X + _
y3 * objOriginalLine.TransformMatrix.TransX.Y + _
varDatLinePoint3.Z * objOriginalLine.TransformMatrix.TransX.Z + _
objOriginalLine.Coordinate.X
varDatLinePoint3.Y = x3 * objOriginalLine.TransformMatrix.TransY.X + _
y3 * objOriginalLine.TransformMatrix.TransY.Y + _
varDatLinePoint3.Z * objOriginalLine.TransformMatrix.TransY.Z + _
objOriginalLine.Coordinate.Y
varDatLinePoint3.Z = x3 * objOriginalLine.TransformMatrix.TransZ.X + _
y3 * objOriginalLine.TransformMatrix.TransZ.Y + _
varDatLinePoint3.Z * objOriginalLine.TransformMatrix.TransZ.Z + _
objOriginalLine.Coordinate.Z
varDatLinePoint4.X = varDatLinePoint4.X * objOriginalLine.TransformMatrix.TransX.X + _
y4 * objOriginalLine.TransformMatrix.TransX.Y + _
varDatLinePoint4.Z * objOriginalLine.TransformMatrix.TransX.Z + _
objOriginalLine.Coordinate.X
varDatLinePoint4.Y = x4 * objOriginalLine.TransformMatrix.TransY.X + _
y4 * objOriginalLine.TransformMatrix.TransY.Y + _
varDatLinePoint4.Z * objOriginalLine.TransformMatrix.TransY.Z + _
objOriginalLine.Coordinate.Y
varDatLinePoint4.Z = x4 * objOriginalLine.TransformMatrix.TransZ.X + _
y4 * objOriginalLine.TransformMatrix.TransZ.Y + _
varDatLinePoint4.Z * objOriginalLine.TransformMatrix.TransZ.Z + _
objOriginalLine.Coordinate.Z
If varDatLineColor = "16" Then
varDatLineColor = objOriginalLine.LineColor
End If
End Select
End Sub
''' <summary>
''' Method to reversewind this line
''' </summary>
''' <remarks></remarks>
Public Sub ReverseWinding()
Dim x1, x2, z1, y1, y2, z2 As Double
Dim x3, x4, z3, y3, y4, z4 As Double
Try
Select Case Me.LineType
Case LDraw_DatLineType.Comment
Case LDraw_DatLineType.Line
Case LDraw_DatLineType.OptLine
Case LDraw_DatLineType.Quad
'save values
x1 = varDatLinePoint1.X
y1 = varDatLinePoint1.Y
z1 = varDatLinePoint1.Z
x2 = varDatLinePoint2.X
y2 = varDatLinePoint2.Y
z2 = varDatLinePoint2.Z
x3 = varDatLinePoint3.X
y3 = varDatLinePoint3.Y
z3 = varDatLinePoint3.Z
x4 = varDatLinePoint4.X
y4 = varDatLinePoint4.Y
z4 = varDatLinePoint4.Z
'Change BFC of that line
If varDatLineBFC = "CW" Then
varDatLineBFC = "CCW"
Else
varDatLineBFC = "CW"
End If
'Change the point of that line
varDatLinePoint1.X = x4
varDatLinePoint1.Y = y4
varDatLinePoint1.Z = z4
varDatLinePoint2.X = x3
varDatLinePoint2.Y = y3
varDatLinePoint2.Z = z3
varDatLinePoint3.X = x2
varDatLinePoint3.Y = y2
varDatLinePoint3.Z = z2
varDatLinePoint4.X = x1
varDatLinePoint4.Y = y1
varDatLinePoint4.Z = z1
Case LDraw_DatLineType.Subpart
'Nothing to do
Case LDraw_DatLineType.Triangle
'save values
x1 = varDatLinePoint1.X
y1 = varDatLinePoint1.Y
z1 = varDatLinePoint1.Z
x2 = varDatLinePoint3.X
y2 = varDatLinePoint3.Y
z2 = varDatLinePoint3.Z
'Change BFC of that line
If varDatLineBFC = "CW" Then
varDatLineBFC = "CCW"
Else
varDatLineBFC = "CW"
End If
'Change the point of that line
varDatLinePoint1.X = x2
varDatLinePoint1.Y = y2
varDatLinePoint1.Z = z2
varDatLinePoint3.X = x1
varDatLinePoint3.Y = y1
varDatLinePoint3.Z = z1
End Select
Catch ex As Exception
MessageBox.Show("Error in cls_LDraw_Line in ReverseWinding" & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub