Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.02 KB | None | 0 0
  1. local point1 = {3, 1}
  2. local point2 = {2, 2}
  3. local point3 = {3, 2}
  4.  
  5. function distance(a, b)
  6.     local dist = math.sqrt(math.abs(((a[1]-b[1])^2) + ((a[2]-b[2])^2)))
  7.     return dist
  8. end
  9.  
  10. function angles(first,second, third)
  11.     local dista = distance(first,second)
  12.     local distb = distance(second,third)
  13.     local distc = distance(third, first)
  14.     local anglec = math.acos(((dista^2) + (distb^2) - (distc^2)) / (2*dista*distb))
  15.     local angleb = math.asin(((math.sin(anglec)) / distc) * distb)
  16.     anglec = math.deg(anglec)
  17.     angleb = math.deg(angleb)
  18.     local anglea = 180 - angleb - anglec
  19.     return {anglea, angleb, anglec, dista, distb, distc}
  20. end
  21.  
  22. function findit(point1, point2, point3)
  23.     local tab = angles(point1, point2, point3)
  24.     local all = {{tab[1], tab[4]}, {tab[2], tab[5]}, {tab[3], tab[6]}}
  25.     local vals = {"A", "B", "C"}
  26.     for i = 1, 3 do
  27.         print("Angle ".. vals[i] .. " is " .. all[i][1])
  28.         print("Line ".. string.lower(vals[i]) .. " is " .. all[i][2])
  29.     end
  30. end
  31.  
  32. findit(point1, point2, point3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement