Advertisement
Velinquish

Untitled

Apr 14th, 2020
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.73 KB | None | 0 0
  1. --[[
  2.     There are 60 minutes on an analog clock.
  3.     There are 12 hours on an analog clock.
  4.  
  5.     Also note that if it's 5:30, the hours hand isn't on the 5. It's halfway between 5 and 6.
  6.     There are also 60 minutes between each hour, of which there are 12.
  7.     Hence, the math used here. Ask if you need explanation.
  8. --]]
  9.  
  10. local function findAngle(hours, minutes)
  11.     -- The angle of the hours hand
  12.     local hAngle = (hours / 12) * 360 + (minutes / (12 * 60)) * 360
  13.     -- The angle of the minutes hand
  14.     local mAngle = (minutes / 60) * 360
  15.     -- The angle between them - absolute value
  16.     local angle = math.abs(hAngle - mAngle)
  17.    
  18.     -- There's a larger angle and a smaller angle - return the smallest
  19.     return angle > 180 and 360 - angle or angle
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement