Add vector.angleTo(x,y, u,v)

This commit is contained in:
Matthias Richter 2013-07-30 11:55:06 +02:00
parent 1f9a7f1f52
commit 015ff8a23a

View File

@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
]]-- ]]--
local sqrt, cos, sin = math.sqrt, math.cos, math.sin local sqrt, cos, sin, atan2 = math.sqrt, math.cos, math.sin, math.atan2
local function str(x,y) local function str(x,y)
return "("..tonumber(x)..","..tonumber(y)..")" return "("..tonumber(x)..","..tonumber(y)..")"
@ -120,6 +120,10 @@ local function trim(maxLen, x, y)
return x * s, y * s return x * s, y * s
end end
local function angleTo(x,y, u,v)
return atan2(y - (v or 0), x - (u or 0))
end
-- the module -- the module
return { return {
str = str, str = str,
@ -149,5 +153,6 @@ return {
perpendicular = perpendicular, perpendicular = perpendicular,
project = project, project = project,
mirror = mirror, mirror = mirror,
trim = trim trim = trim,
angleTo = angleTo,
} }