
11-15-2003, 05:46 AM
|
 |
Contributor
|
|
Join Date: May 2003
Location: Oostkamp - Belgium
Posts: 730
|
|
Maths Angle problem
|
Okay i've written this code for a game, to get an angle out of two coordinates (or a vector if you like that more). The problem is that somehow, this function only returns 1 or 0. This simply can't be correct. When uncomment the last line, i do get the angle in my debug window.
Anyone has an idea why?
here's my code:
Code:
Const pi As Long = 3.14159265358979
Public Const Rad As Long = pi / 180
Public Const Deg As Long = 180 / pi
Public Function GetAngle(Origin As Coordinate, Co2 As Coordinate, Optional InDegr As Boolean = False) As Long
Dim Upper As Long, Lower As Long
Upper = (Origin.Y - Co2.Y)
Lower = (Origin.X - Co2.X)
If Not Lower = 0 Then
If InDegr = True Then
GetAngle = Atn(Upper / Lower) * Deg
Else
GetAngle = Atn(Upper / Lower)
End If
Else
If Upper > 0 Then
If InDegr = True Then
GetAngle = 90
Else
GetAngle = pi / 2
End If
Else
If InDegr = True Then
GetAngle = 270
Else
GetAngle = (3 * pi) / 2
End If
End If
End If
'Debug.Print Atn(Upper / Lower)
End Function
thanx a lot for any help
mathijsken
|
Last edited by Mathijsken; 11-15-2003 at 07:28 AM.
Reason: Little mistake in the "if upper > 0"-part, still isn't working anyways
|