add function angle()

returns the angle between a vector and the default rotation
This commit is contained in:
out-of-pixel 2013-06-29 17:39:03 +02:00
parent e9b86ef2d5
commit 4afcac5b36

View File

@ -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