Sergey
Sergey

Reputation: 8071

How to calculate for which quadrant is belong (coordinates) latitude and latitude point

I know top left corner and also I know the width and height of the square. Note (calculation) can be rounded because the distance just 0.25 mile. Also I know the point which is inside that square. How to calculate for which square the given point is belong? I've attached the picture which will show what I mean. enter image description here

Upvotes: 0

Views: 2557

Answers (1)

Wond3rBoi
Wond3rBoi

Reputation: 293

If you know the point p = (x,y), then just use some nested if statements...

if(x >= 0 ) {
  if( y >= 0 ) 
    return QuadrantB;
  else
    return QuadrantD;
}
else {
  if( y >= 0 )
    return QuadrantA;
  else
    return QuadrantC;
}

You might want to change whether or not the conditionals inside the if statement are inclusive or exclusive.

Note: This is assuming the center of all four quadrants is defined as (0,0). If the top left is defined as (0,0), then just subtract 0.25/2 = 0.125 from both x and y to get the point in the coordinate frame defined by (0,0) being the center of all four quadrants.

This sort of analysis is used to compute the quadrant in the commonly used atan2 function, which returns the angle of the vector that starts at the origin and ends at point (x,y): http://en.wikipedia.org/wiki/Atan2.

Upvotes: 1

Related Questions