• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Formula to calculate coordinates between 2 bounds in Java

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have two coordinates latitude and longitude value provided.
I wanted to calculate which all coordinates sets fall inside the area it covers.
For example i have attached an image, we have latitude & longitude for N-E and another set of lat-long for S-O, what is the formula by which i can calculate which coordinates fall inside the area it covers .

Thanks!
Shri
latlong.PNG
[Thumbnail for latlong.PNG]
 
Marshal
Posts: 8418
606
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those two points looks like representing rectangle, which could be constructed by two its opposite corner points. Those sets of coordinates as you call them, could be an array of points, where each point is represented by its two x and y axes coordinates in 2 dimensional coordinates grid.
You can check this Rectangle class, you might find some useful methods to accomplish what you want, or you need to implement everything yourself?

Formula you need to workout yourself, this is the most interesting part of your exercise how you're going to do that. Surely there is more than one way.
 
Liutauras Vilda
Marshal
Posts: 8418
606
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Liutauras Vilda
Marshal
Posts: 8418
606
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One way comes to my mind to solve this, could be:
leftLowerPoint is the red point from your graph on the left hand side.
rightUpperPoint is the red point from your graph on the right hand side.

bluePoint is the cross you need to check if it is in that area of those covered red points.

By assuming you know each point x and y axes coordinates, you can check, if:

leftLowerPoint x-axis coordinate is less or equal bluePoint x-axis coordinate AND leftLowerPoint y-axis coordinate is less or equal bluePoint y-axis coordinate AND
rightUpperPoint x-axis coordinate is greater or equal bluePoint x-axis coordinate AND rightUpperPoint y-axis coordinate is greater or equal bluePoint y-axis coordinate

If it is true, then your point is in that range. As I said, this is the first thing came to my mind. I believe there are much more ways to find out that.
 
Marshal
Posts: 76452
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use the same technique for rectangular coordinates and for latitude and longitude which are curved.

And welcome again
 
Saloon Keeper
Posts: 26039
186
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The closer you are to the equator, the more accurate use of a bounding rectangle will be. Near the poles, the bounding area becomes more trapezoidal, in the immediate polar vicinity, and at the poles themselves, it's technically a circle, so just checking longitude would make for a quick test.

For a more precise, but rapid calculation, you can probably use rectangles up to about 60 degrees N and S, it's up to you how you want to address stuff beyond that. On the Earth, most places of interest are probably below 60 degrees.

You can also use the rectangle test for a rough exclusion, then use a more detailed (slower) algorithm for winning candidates. Which algorithm you might use depends on whether the final bounding area is rectangular (more or less), circular, or something else and gets you solidly into 3-dimensional surface geometry maths.

All of the above are based on the idea that, given a point, you're trying to prove proximity to some other point or area. The actual question read more like "I want to find all points within this area", and since longitude and latitude are non-integer values, the potential number of answers to that question is infinite, allowing for arbitrary cutoff of precision.

If you're attempting to find the area (of whatever shape) is centered on a supplied point, you'd more or less turn the above suggestions inside out.
 
Not looking good. I think this might be the end. Wait! Is that a tiny ad?
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic