Advertisement
R167

Lua: Circle API

Mar 20th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. pi = math.pi
  2.  
  3. function inscribedPoly(_radius,_sides,_units)
  4.   local _angle = (math.pi * (_sides - 2)) / (2 * _sides)
  5.   local _height = math.sin(_angle) * _radius
  6.   local _baseRight = math.cos(_angle) * _radius
  7.   local _area = _height * _baseRight * _sides
  8.   if _units then
  9.     print(_area.." "..tostring(_units).."^2")
  10.   end
  11.   return _area
  12. end
  13.  
  14. function circumscribedPoly(_radius,_sides,_units)
  15.   local _angle = (math.pi * (_sides - 2)) / (2 * _sides)
  16.   local _height = _radius
  17.   local _baseRight = _height / math.tan(_angle)
  18.   local _area = _height * _baseRight * _sides
  19.   if _units then
  20.     print(_area.." "..tostring(_units).."^2")
  21.   end
  22.   return _area
  23. end
  24.  
  25. function sidePoly(_sides,_length,_units)
  26.    local _angle = (math.pi * (_sides - 2)) / (2 * _sides)
  27.    local _baseRight = _length / 2
  28.    local _height = _baseRight * math.tan(_angle)
  29.    local _area = _height * _baseRight * _sides
  30.    if _units then
  31.        print(_area.." "..tostring(_units).."^2")
  32.     end
  33.     return _area
  34. end
  35.  
  36. function area(_radius) return math.pi * (_radius ^ 2) end
  37.  
  38. function circumference(_radius) return math.pi * _radius * 2 end
  39.  
  40. function diameter(_radius) return _radius * 2 end
  41.  
  42. function sphereVolume(_radius) return math.pi * (_radius ^ 3) * (4/3) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement