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

  • Home
  • SEARCH
  • 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 6547755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:52:11+00:00 2026-05-25T11:52:11+00:00

given is a Cartesian coordinate system and a point(x,y) within this system. For example

  • 0

given is a Cartesian coordinate system and a point(x,y) within this system. For example a point p has the coordinates (-12,2):

                  |
                  |
      p           |
                  |
------------------+------------------>
                  |
                  |
                  |
                  |

Now I need a function/algorithm that calculates the opposite “direction” (north, east, south, west) from the coordinate system’s center (0,0) based on the given point. In our example the best opposite direction to choose would be EAST, following the X-axis to the right.

However, in some situations within my application not all directions are an option to choose, in such a case the next-best direction has to be chosen. In our example, if EAST would not be possible, then the next-best direction would be SOUTH (then NORTH, then WEST).

I could solve this with some if-statements, but that does not seem to be very elegant.
Any other (better) ideas?

  • 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-25T11:52:11+00:00Added an answer on May 25, 2026 at 11:52 am

    Use the dot product of your vector (x, y) with the unit vectors along the four directions

    (1, 0), (-1, 0), (0, 1), (0, -1).
    

    The smallest number corresponds the direction you want. Then the second smallest, and so on.

    This works for any directions not just E, W, S and N – you just need to pick unit vectors along the desired directions and compare the dot products

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

Sidebar

Related Questions

I want to convert some point coordinates which are given in a cartesian system
Given this example, how do we ensure that the thread instance has been freed?
Given an undirected graph in which each node has a Cartesian coordinate in space
Suppose I am given number of lines segments in Cartesian coordinate system.Each line is
This question asks how to compute the Cartesian product of a given number of
Given a series of GPS coordinate pairs, I need to calculate the area of
I've been trying to do a function that returns the Cartesian Product of n
Need Hints to design an efficient algorithm that takes the following input and spits
Given a polygon (not necessary convex) in the Cartesian coordinate, i wonder if there
Given an absolute or relative path (in a Unix-like system), I would like to

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.