Fix #25: vector:angleTo() returns wrong angle.

This commit is contained in:
Matthias Richter 2013-11-04 22:04:16 +01:00
parent cea730deac
commit 32e0aaeaa6
2 changed files with 8 additions and 3 deletions

View File

@ -121,7 +121,10 @@ local function trim(maxLen, x, y)
end
local function angleTo(x,y, u,v)
return atan2(y - (v or 0), x - (u or 0))
if u and v then
return atan2(y, x) - atan2(v, u)
end
return atan2(y, x)
end
-- the module

View File

@ -175,8 +175,10 @@ function vector:trim_inplace(maxLen)
end
function vector:angleTo(other)
other = other or zero
return atan2(self.y - other.y, self.x - other.x)
if other then
return atan2(self.y, self.y) - atan2(other.y, other.x)
end
return atan2(self.y, self.y)
end
function vector:trimmed(maxLen)