I got a point with latitude 'x' and longitude 'y' using decimals. The point is centered in a square, the length to each side is 12 meters. How do I find the latitudes and longitudes of each corner of the square? I program in Java, but I appreciate any pseudo-code. :-)
After reading articles on the matter, I guess that a change of 'd'-meters is equal to 'e'-degrees (in decimal)..? If so, what is the "conversion-rate"?
I do not know if this helps, but given that it is 12 meters to each side, each corner has to be 16,97 meters from the point.
In advance, thanks :-)
Store your center point lat/lon, as well as the distance to the corner (use some trig to figure this), and the radius of the earth in meters. Your bearing in degrees will be 45 to give you the top-right, 115 for top-left, and so on. Use the fancy math below to find the lat/long of your desired corner in decimal format. Convert to degrees by multiplying each by 180/PI
lat1 = centerPoint.lat * ( Math.PI / 180 ); //Only do this if you need to convert from deg. to dec.
lon1 = centerPoint.lng * ( Math.PI / 180 ); //Only do this if you need to convert from deg. to dec.
d = distance;
R = EARTHS_RADIUS_IN_METERS;
brng = bearingInDegrees * ( Math.PI / 180 );
lat2 = Math.asin( Math.sin( lat1 ) * Math.cos( d / R ) + Math.cos( lat1 ) * Math.sin( d / R ) * Math.cos( brng ) );
lon2 = lon1 + Math.atan2( Math.sin( brng ) * Math.sin( d / R ) * Math.cos( lat1 ), Math.cos( d / R ) - Math.sin( lat1 ) * Math.sin( lat2 ) );
return new LatLong( lat2 * ( 180 / Math.PI ), lon2 * ( 180 / Math.PI ) );
Here's a solution using GeographicLib, a library that I wrote:
// Assumes GeographicLib, http://geographiclib.sf.net, is installed
//
// Compile and link with
// g++ -o foo foo.cpp -L /usr/local/lib -Wl,-rpath=/usr/local/lib -lGeographic
#include <GeographicLib/Geodesic.hpp>
#include <iostream>
#include <iomanip>
using namespace GeographicLib;
using namespace std;
int main() {
double lat1, lon1, side;
cin >> lat1 >> lon1 >> side;
cout << fixed << setprecision(14);
double s12 = sqrt(0.5) * side;
const Geodesic& g = Geodesic::WGS84;
for (int i = 0; i < 4; ++i) {
double azi1 = i * 90 - 135;
double lat2, lon2;
g.Direct(lat1, lon1, azi1, s12, lat2, lon2);
cout << lat2 << " " << lon2 << "\n";
}
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With