[Gambas-user] Math query
Martín
mbelmonte at belmotek.net
Mon Jun 5 18:05:54 CEST 2023
El 5/6/23 a las 13:59, Fabien Bodard escribió:
> I need help
>
> I have two vector
> Object (px,py,dx,dy)
> Player (px,py,dx,dy)
>
> I need to know the angle between player and object vector in 360deg
>
> Easy for 180.. but 360 I'm stuck
But the absolute angle between two vectors (a1) will always be 0, 180 or
something in between, if you want to know the angle in the other scan
direction a2 = 360 - a1.
to calculate angle between 2 vectors in the plane:
'' Angle in radians from +x axis
Public Function Angle(af1 As Float[], af2 As Float[]) As Float
Dim a As Float
Dim b As Float
Dim r As Float
a = (af2[1] - af1[1])
b = (af2[0] - af1[0])
If b <> 0 Then
r = ATan(a / b)
Endif
Return r
End
More information about the User
mailing list