0

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

Sergey
  • 7,933
  • 16
  • 49
  • 77

1 Answers1

1

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.

Wond3rBoi
  • 293
  • 3
  • 11
  • ok, maybe it will work. But how to get the latitude and logitude for the top right corner of the my square. If we know latitude and longitude for the top left corner? – Sergey Sep 16 '13 at 18:24
  • You can see this post: http://stackoverflow.com/questions/1253499/simple-calculations-for-working-with-lat-lon-km-distance. It gives an approximate conversion between lat/long degrees and km. You can use that conversion factor to build a conversion factor between lat/long degrees and miles, and since you know the top left corner and the translation you need in miles, you should be set. I wouldn't worry about the error caused by the Earth being a sphere as opposed to a flat plane because your distance is so small. – Wond3rBoi Sep 16 '13 at 18:35
  • 1
    How are you getting the top left corner's coordinates? Are you using the Google Maps Javascript API v3? If you know the bounds, you know the North East (top right) and South West (bottom left), from those coordinates you can easily calculate the coordinates of the missing two corners. – geocodezip Sep 16 '13 at 18:47
  • I know top left corner like this: (49.006179726875, -97.46811767375), how to get top right and other corners? – Sergey Sep 16 '13 at 19:05
  • Is it possible to get the latitude and longitude of the right top corner if I know the distance between top left corner and top right corner? – Sergey Sep 16 '13 at 19:21
  • 1
    I'm pretty sure my first comment already answered that question and provided a link that shows how to do it. Here's another link showing the same thing: http://stackoverflow.com/questions/1125144/how-do-i-find-the-lat-long-that-is-x-km-north-of-a-given-lat-long – Wond3rBoi Sep 16 '13 at 19:37
  • Sorry your answer is not very clear for me. Let's talk by example. We have point: (49.006179726875, -97.46811767375) which and distance 0.25 miles. Which coordinates will be for top right corner – Sergey Sep 16 '13 at 19:41
  • look at the link I provided in my 2nd comment. The link has the exact computation you need to perform. All you'll have to do is convert miles to km. – Wond3rBoi Sep 16 '13 at 19:53
  • Thank you! I've eventually figured it out :) – Sergey Sep 16 '13 at 20:06