Created
March 7, 2013 08:40
-
-
Save mebens/5106500 to your computer and use it in GitHub Desktop.
Revisions
-
Michael Ebens created this gist
Mar 7, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ #!/usr/bin/env lua function exit(msg, code) print(msg) os.exit(code or 1) end function main() if #arg < 4 then exit("Please provide a magnitude and angle for two polar vectors") end local m1, a1, m2, a2 = unpack(arg) m1, a1, m2, a2 = tonumber(m1), math.rad(tonumber(a1)), tonumber(m2), math.rad(tonumber(a2)) local x1 = m1 * math.cos(a1) local y1 = m1 * math.sin(a1) local x2 = m2 * math.cos(a2) local y2 = m2 * math.sin(a2) local x, y = x1 + x2, y1 + y2 local angle = math.deg(math.atan2(y, x)) if angle < 0 then angle = angle + 360 end print("Magnitude: " .. math.sqrt(x ^ 2 + y ^ 2)) print("Angle: " .. angle) end main()