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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:24:21+00:00 2026-06-18T03:24:21+00:00

I have a data values which vary from +PI to -PI radian. I need

  • 0

I have a data values which vary from +PI to -PI radian.

I need to get minimum rotation (in radians) required to go from old value to new value like:

float rotationRequired(float oldValue, float newValue){
      return newValue - oldValue;
}

but simply subtracting won’t do, because to go from -179 degree to +179 degree one does not need to rotate full circle around, just 2 degree clockwise. Because -PI = +PI in a circle are technically same rotation. Also the values can be in any range, i.e 740 = 360 + 360 + 20, hence only 20.

I’m thinking about breaking values into sin and cos values, subtract and then atan :

double oldY =  Math.sin(oldValue);
double oldX =  Math.cos(oldValue);

double newY =  Math.sin(newValue);
double newX =  Math.cos(newValue);

float delta = (float) Math.atan2( (newY - oldY),(newX - oldX) );

But still its not giving correct results, can anyone suggest another method ?

  • 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-18T03:24:22+00:00Added an answer on June 18, 2026 at 3:24 am

    I converted angles to degrees and used this method to suggest what minimum rotation is required and in what direction:

    public static int suggestRotation(int o, int n){
        //--convert to +0 to +360 range--
        o = normalize(o);
        n = normalize(n);
    
        //-- required angle change --
        int d1 = n - o;
    
        //---other (360 - abs d1 ) angle change in reverse (opp to d1) direction--
        int d2 = d1 == 0 ? 0 : Math.abs(360 - Math.abs(d1))*(d1/Math.abs(d1))*-1;
    
        //--give whichever has minimum rotation--
        if(Math.abs(d1) < Math.abs(d2)){
            return d1;
        }else {
            return d2;
        }
    
    }
    
    private static int normalize(int i){
        //--find effective angle--
        int d = Math.abs(i) % 360;
    
        if(i < 0){
        //--return positive equivalent--
            return 360 - d;
        }else {
            return d;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a manager class, which update json data from web, get values... The
I have a question about retrieving data values which are sent from a web
I have a data table which already has some values, plus it is getting
I have a streaming input which has repeated values. I can use any data
I have a universal data type, which is passed by value, but does not
I have a datatable which contains yearly data saved. e.g. dtDate Value 2010-01-01 00:00:00.000
I have the following LINQ Select which does not work. Data.Select(d => d.Value.IsDirty =
Scenario: Drawing a graph. Have data points which range from A to B, and
I have a 1 dimensional data set with some no data values which are
I need to extract parts of a dataframe, using the values which I have

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.