MorphuisOGrady
Member
Hi Guys,
I need to write a routine to calculate direction based on 2 Velocities. I'm trying to implement an ATAN2 VB script i found online into ladder as follows:
If y > 0 Then
If x >= y Then
Atan2 = Atn(y / x)
ElseIf x <= -y Then
Atan2 = Atn(y / x) + Pi
Else
Atan2 = Pi / 2 - Atn(x / y)
End If
Else
If x >= -y Then
Atan2 = Atn(y / x)
ElseIf x <= y Then
Atan2 = Atn(y / x) - Pi
Else
Atan2 = -Atn(x / y) - Pi / 2
End If
End If
The problem i have is here: ElseIf x <= -y Then
I want to use a LEQ instruction but how can I make Y a minus value?
I need to write a routine to calculate direction based on 2 Velocities. I'm trying to implement an ATAN2 VB script i found online into ladder as follows:
If y > 0 Then
If x >= y Then
Atan2 = Atn(y / x)
ElseIf x <= -y Then
Atan2 = Atn(y / x) + Pi
Else
Atan2 = Pi / 2 - Atn(x / y)
End If
Else
If x >= -y Then
Atan2 = Atn(y / x)
ElseIf x <= y Then
Atan2 = Atn(y / x) - Pi
Else
Atan2 = -Atn(x / y) - Pi / 2
End If
End If
The problem i have is here: ElseIf x <= -y Then
I want to use a LEQ instruction but how can I make Y a minus value?