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 6749965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:45:10+00:00 2026-05-26T12:45:10+00:00

I have a dial which I drag around a circle to give me a

  • 0

I have a dial which I drag around a circle to give me a reading between 0 and 1.

Something like this:

dx = mouseX-centerX;
        dy = mouseY-centerY;
        rad = Math.atan2(dy,dx);

        rad += offset;

        Tweener.addTween(knob,{y:centerY - Math.cos(rad)*radius, time:.1,  transition:"easeOutSine"});
        Tweener.addTween(knob,{x:centerX + Math.sin(rad)*radius, time:.1,  transition:"easeOutSine"});
        knob.rotation = rad * 180 / Math.PI;

This work’s great, except when the slider goes from 359 degrees to 1 degree, my value between 0 and 1 returns to zero. (Which makes sense, as the value is based on the angle of my slider)

I’m trying to find a way for the dial to move from 359 degrees to 361 and onwards basically.

In my head: I need to check if the next value of my mouse drag goes past the 360 degree point and add 360 to the total, to stop it returning to zero and continue to 361 degrees.

I just cant work out how to put this into code…

  • 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-05-26T12:45:10+00:00Added an answer on May 26, 2026 at 12:45 pm

    On each frame when you are rotating the knob, check the change in angular distance instead of direct angle.

    Save the previous frames angle and see if the difference is positive or negative.

    var rad = Math.atan2(dy, dx);
    var diff = rad - oldRad;
    oldRad = rad;
    if( diff > Math.PI )
      diff -= Math.PI * 2;
    if( shortestAngle < -Math.PI )
      diff += Math.PI * 2;
    

    diff should contain a value that if it’s been rotated to the right, is positive (or negative if rotated left). Simply add that to the total angle.

    There might be some errors in the code (took it from an old project), but that’s the gist of it 🙂

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have rotated a dial around its center with the helop from the link
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
I am trying to create application, which sould work this way: User dial a
ID_FLOWER_128X128_JPG ID_APPLE_100X100_ICO ID_ORANGE_64X64_PNG ID_SUN_DIAL_64X64_PNG ID_COMPUTER_16X16_ICO I have several constants which have been declared like
I have used the following code to dial a number: DataBaseHelper db; db=new DataBaseHelper(PanicService.this);
I'd like to know whether something like this has been done before: I've recently
I would like to check in which country the user is - I have
Possible Duplicate: Enable GPS programatically like Tasker I have a code for dial and
I am trying to dial a phone number from php (i have a client

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.