Ad

Thursday, February 12, 2009

Angle Between Lines

Just some reminders to myself. VBA.

Dim dPt1(0 To 2) As Double
Dim dPt2(0 To 2) As Double
Dim dAng As Double

Pi equation
Dim pi
pi = 4 * Atn(1)

dPt1(0) = oStructure.ConnectedPipe(i - 1).StartPoint.X
dPt1(1) = oStructure.ConnectedPipe(i - 1).StartPoint.Y
dPt2(0) = oStructure.ConnectedPipe(i - 1).EndPoint.X
dPt2(1) = oStructure.ConnectedPipe(i - 1).EndPoint.Y
dPt3(0) = oStructure.ConnectedPipe(j).StartPoint.X
dPt3(1) = oStructure.ConnectedPipe(j).StartPoint.Y
dPt4(0) = oStructure.ConnectedPipe(j).EndPoint.X
dPt4(1) = oStructure.ConnectedPipe(j).EndPoint.Y

Make sure the lines/points start at the same point to make sure the angle calculated is correct. Absolute in case the angle is negative. 2pi - dAng to get the other angle associated. Much easier than

If dPt1(0) = dPt3(0) And dPt1(1) = dPt3(1) Then
dAng = Abs(ThisDrawing.Utility.AngleFromXAxis(dPt1, dPt2) - ThisDrawing.Utility.AngleFromXAxis(dPt3, dPt4))
ElseIf dPt2(0) = dPt3(0) And dPt2(1) = dPt3(1) Then
dAng = Abs(ThisDrawing.Utility.AngleFromXAxis(dPt2, dPt1) - ThisDrawing.Utility.AngleFromXAxis(dPt3, dPt4))
ElseIf dPt2(0) = dPt4(0) And dPt2(1) = dPt4(1) Then
dAng = ThisDrawing.Utility.AngleFromXAxis(dPt2, dPt1) - ThisDrawing.Utility.AngleFromXAxis(dPt4, dPt3)
ElseIf dPt1(0) = dPt4(0) And dPt1(1) = dPt4(1) Then
dAng = Abs(ThisDrawing.Utility.AngleFromXAxis(dPt2, dPt1) - ThisDrawing.Utility.AngleFromXAxis(dPt3, dPt4))
End If

No comments:

LinkWithin

Blog Widget by LinkWithin

Ad