Search code examples
luaangle

Degree value to two float variables


I need help creating a function to convert an angle to two float variables.

Here are some examples of the outputs:

  • 0 degrees = {1, 0}
  • ~31.0760 degrees = {~0.92823970, ~0.37198266}
  • 45 degrees= {~0.70707070, ~0.70707070}
  • 90 degrees = {0, 1}
  • 135 degrees = {~-0.707070707, ~0.707070707}
  • 180 degrees = {-1, 0}
  • 225 degrees = {~-0.707070707, ~-0.707070707}
  • ~240.2409 degrees = {~-0.35347452, ~-0.93544417}
  • 270 degrees = {0, -1}
  • 315 degrees = {~0.70707070, ~-0.70707070}

Solution

  • I'm not entirely sure if you are hung up on the syntax or the algorithmic part of this problem. I figure the syntax is simpler to look up so I will offer the simple calculation.

    Your tuple will be calculated using the lua math functions: math.rad, math.cos, math.sin

    {math.cos(math.rad(degrees)), math.sin(math.rad(degrees))}
    

    Hope that helps