Skip to content

Instantly share code, notes, and snippets.

@AngeloYazar
Created January 12, 2012 19:55
Show Gist options
  • Save AngeloYazar/1602724 to your computer and use it in GitHub Desktop.
Save AngeloYazar/1602724 to your computer and use it in GitHub Desktop.
distance in lua
function distance( x1, y1, x2, y2 )
return math.sqrt( (x2-x1)^2 + (y2-y1)^2 )
end
function distanceSquared( x1, y1, x2, y2 )
return (x2-x1)^2 + (y2-y1)^2
end
function lineDistance( x, y, dx, dy, u, v )
local wx,wy = u-x, v-y
return math.sqrt((wx^2 + wy^2)-(((dx*wx+dy*wy)^2)/(dx^2+dy^2))) --MATHAMAGICAL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment