Okay, what the hell is going on here?
Function vectorLen(ByVal x As Decimal, ByVal y As Decimal) As Decimal
Return Math.Sqrt(x ^ 2 + y ^ 2)
End Function
Function vectorNorm(ByVal x As Decimal, ByVal y As Decimal) As PointF
Return New PointF(x * vectorLen(x, y), y * vectorLen(x, y))
End Function
Function vectorAddTheta(ByVal x As Decimal, ByVal y As Decimal, ByVal theta As Decimal) As PointF
Try
Dim l As Decimal = vectorLen(x, y)
Dim n As PointF = vectorNorm(x, y)
Dim t As Decimal = Math.Asin(n.Y)
t += theta
Dim nn As PointF = New PointF(Math.Cos(t) * l, Math.Sin(t) * l)
Return nn
Catch
Me.CreateGraphics.DrawString("ERROR IN CALC", Font, Brushes.Red, 32, 32)
End Try
End Function
...
Case 2
'dxy orbital - 2 p orbitals crossed
e1 = vectorAddTheta(120, 0, phaseState * 360)
e1.X *= e1.Y / 120
e1n = vectorAddTheta(e1.X, e1.Y, 45)
e1n.X += 256
e1n.Y += 256
e2n = vectorAddTheta(e1.X, e1.Y, 360 - 45)
e2n.X += 256
e2n.Y += 256
One of these vectorAddTheta's is returning an error that has something to do with a decimal being either too large or too small. 'phaseState' is a value that is always between 0 and 1.