mirror of
https://github.com/vrld/hump.git
synced 2024-11-23 12:24:19 +00:00
add function angle()
returns the angle between a vector and the default rotation
This commit is contained in:
parent
e9b86ef2d5
commit
4afcac5b36
10
vector.lua
10
vector.lua
@ -135,6 +135,16 @@ function vector:rotated(phi)
|
|||||||
return new(c * self.x - s * self.y, s * self.x + c * self.y)
|
return new(c * self.x - s * self.y, s * self.x + c * self.y)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function vector:angle()
|
||||||
|
local a = new(1,0)
|
||||||
|
local angle = math.acos((a*self)/(a:len()*self:len()))
|
||||||
|
if self.y < 0 then
|
||||||
|
return -angle
|
||||||
|
else
|
||||||
|
return angle
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function vector:perpendicular()
|
function vector:perpendicular()
|
||||||
return new(-self.y, self.x)
|
return new(-self.y, self.x)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user