Add projection and perpendicular

This commit is contained in:
Matthias Richter 2010-08-17 13:17:01 +02:00
parent 6315155955
commit 66c0f92a30

View File

@ -102,3 +102,12 @@ end
function Vector:rotated(phi)
return self:clone():rotate_inplace(phi)
end
function Vector:perpendicular()
return vector(-self.y, self.x)
end
function Vector:projectOn(v)
assert(isvector(v), "invalid argument: cannot project onto anything other than a vector.")
return (self * v) * v / v:len2()
end