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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:22:19+00:00 2026-05-21T05:22:19+00:00

I have the following code, and I can see that there is a connection

  • 0

I have the following code, and I can see that there is a connection between the values. I can however not get my head together and figure out how to remove the switch statements with some add subtract modelo haxx. Would really appriciate some help to get this method smoother.

The heading variable is either 0, 1, 2 or 3.

public static int getRotation(Point currentPoint, Point nextPoint, int heading) {
    int rotation = -1;
    if(currentPoint.getX() < nextPoint.getX()) /* DRIVE WEST */  {
        switch(heading) {
            case 0: rotation = 1; break;
            case 1: rotation = 0; break;
            case 2: rotation = 3; break;
            case 3: rotation = 2; break;
        }
    } else if(currentPoint.getX() > nextPoint.getX()) /* DRIVE EAST */ {
        switch(heading) {
            case 0: rotation = 3; break;
            case 1: rotation = 2; break;
            case 2: rotation = 1; break;
            case 3: rotation = 0; break;
        }
    } else if(currentPoint.getY() < nextPoint.getY()) /* DRIVE  NORTH */ {
        switch(heading) {
            case 0: rotation = 0; break;
            case 1: rotation = 3; break;
            case 2: rotation = 2; break;
            case 3: rotation = 1; break;
        }
    }  else if(currentPoint.getY() > nextPoint.getY()) /* DRIVE SOUTH */ {
        switch(heading) {
            case 0: rotation = 2; break;
            case 1: rotation = 1; break;
            case 2: rotation = 0; break;
            case 3: rotation = 3; break;
        }
    }

    return rotation;
}

EDIT: I did forget to mention that nextPoint can only be +-x or y compared to currentPoint. if currentPoint is (0,0) newPoint must be either (-1,0), (1,0), (0,-1) or (0,1).

  • 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-21T05:22:19+00:00Added an answer on May 21, 2026 at 5:22 am

    You could try.

    int eastWest = Double.compare(currentPoint.getX(), nextPoint.getX()) 
    if (eastWest == 0) {
        int northSouth = Double.compare(currentPoint.getX() , nextPoint.getX()) 
        /* DRIVE NORTH (-1), SOUTH (+1) */ 
        if (northSouth == 0)
           rotation = -1;
        else
           rotation = (5 + northSouth - heading) % 4;
    } else {
        /* DRIVE WEST (-1), EAST (+1) */  
        rotation = heading ^ (2 + eastWest);
    }
    

    Note: I would expect to see some symetry to these functions are each direction appears to have a different combination and doesn’t sound right.

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

Sidebar

Related Questions

I have a simple 3D cube that I can rotate using the following code:
Following on from this question I now have code that can attach to a
According to what I have found so far, I can use the following code:
We have similar code to the following in one of our projects. Can anyone
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I'm trying to use opengl in C#. I have following code which fails with
I have the following code in a web.config file of the default IIS site.
I have the following code: $bind = new COM(LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local); When I execute it from
I have the following code snippet. $items['A'] = Test; $items['B'] = Test; $items['C'] =

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.