Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7818175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:29:32+00:00 2026-06-02T06:29:32+00:00

Note : I’m using Lua. So, I’m trying to find out the degrees between

  • 0

Note: I’m using Lua.

So, I’m trying to find out the degrees between two points on a circle. The problem is between something like 340 and 20, where the correct answer is 40 degrees, but doing something like

function FindLeastDegrees(s, f) 
    return ((f - s+ 360) % 360) 
end 

print(FindLeastDegrees(60, 260))

-- S = Start, F = Finish (In degrees)

Which works all all situations except for when trying to figure out the distance between the two. This below code is my next failed attempt.

function FindLeastDegrees(s, f) 
    local x = 0 
    if math.abs(s-f) <= 180 then 
        x = math.abs(s-f) 
    else 
        x = math.abs(f-s)  
    end 
return x
end

print(FindLeastDegrees(60, 260))

I then tried:

function FindLeastDegrees(s, f) 
    s = ((s % 360) >= 0) and (s % 360) or 360 - (s % 360); 
    f = ((f % 360) >= 0) and (f % 360) or 360 - (f % 360); 
    return math.abs(s - f) 
end 

print(FindLeastDegrees(60, 350))

--> 290 (Should be 70)

So that failed. :/

So how would you find the shortest amount of degrees between two other degrees, and then if you should go clockwise or counterclockwise (Add or subtract) to get there. I’m entirely confused.

A few examples of what I’m trying to do…

FindLeastDegrees(60, 350)
--> 70

FindLeastDegrees(-360, 10)
--> 10

Which seems so hard! I know I will have to use…

  1. Modulus
  2. Absolute Values?

I would also like it to return if I should add or subtract to get to the value ‘Finish’.
Sorry for the lengthy description, I think you probably have got it…. :/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:29:33+00:00Added an answer on June 2, 2026 at 6:29 am

    If the degrees are in the 0 to 360 range, the % 360 part can be skipped:

    function FindLeastDegrees(s, f) 
        diff = math.abs(f-s) % 360 ;
        return math.min( 360-diff, diff ) 
    end 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NOTE: The scenario is using 2 entity framework models to sync data between 2
Note: I'm using Windows file servers and .NET If I were to create a
NOTE: I have solved the majority of this problem but have run into a
NOTE : My specific problem is solved (explained at the bottom), but I'll leave
NOTE: This question is only loosely related to tinyxml, however including details like that
Note: This was posted when I was starting out C#. With 2014 knowledge, I
NOTE: I am not set on using VI, it is just the first thing
Note: purely out of curiosity and not for any actual use case. I'm wondering
note: question title is change as discussed in this meta Q&A I'm using the
Note: This might seem like a Super User question at first, but please read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.