lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


To calculate the angle beteween the two vectors, you sould do:

math.atan2(b[2],b[1]) - math.atan2(a[2],a[1])


Alexandre

-----Message d'origine----- From: Miles Bader Sent: Tuesday, April 03, 2012 6:40 AM To: Rena Cc: Lua mailing list Subject: Re: Atan2 and angle between vectors
Rena <hyperhacker@gmail.com> writes:
I just discovered that math.atan2 doesn't handle the case of y=0
properly, at least in Lua 5.1:

a, b = {-1, 0}, {1, 0}
=math.deg(math.atan2(b[2] - a[2], b[1] - a[1]))
0

That is the correct result.

Anyway, Lua's atan2 just calls the C library's atan2, so if you notice
any problem, it's more likely to be with the C library.

-Miles

--
gravity a demanding master ... soft soft snow