Reputation: 6512
I have the following function which plots a Circle given the centroid, but I want the coordinates to be In WGS84.
var coords = new List<Tuple<double, double>>();
const double EARTH_RADIUS_NM = 3437.670013352;
var lat = (latIn * Math.PI) / 180;
var lon = (lonIn * Math.PI) / 180;
double d = radiusIn / EARTH_RADIUS_NM;
for (int x = 0; x <= 360; x++)
{
double brng = (x * Math.PI) / 180;
var latRadians = Math.Asin(Math.Sin(lat) * Math.Cos(d) + Math.Cos(lat) * Math.Sin(d) * Math.Cos(brng));
var lngRadians = lon + Math.Atan2(Math.Sin(brng) * Math.Sin(d) * Math.Cos(lat), Math.Cos(d) - Math.Sin(lat) * Math.Sin(latRadians));
coords.Add(new Tuple<double, double>(latRadians, lngRadians));
}
Upvotes: 1
Views: 2036
Reputation: 2415
The answer to the this old question, which may be of use to others, is that the results in radians need to be converted back to degrees.
The following part of your code converts the degrees to radians:
var lat = (latIn * Math.PI) / 180;
var lon = (lonIn * Math.PI) / 180;
Before you add the results to your List, you need to convert them back to degrees:
var latDegrees = (180/Math.PI) * latRadians;
var lngDegrees = (180/Math.PI) * lngRadians;
coords.Add(new Tuple<double, double>(latDegrees, lngDegrees));
Confirmed to work in a Mapview:
For more info, see the Introduction section at http://www.edwilliams.org/avform.htm
Upvotes: 0
Reputation: 1378
EDIT**: sorry i misunderstood the problem at the start. I don't quite understand your naming convention so I will not write the code initially. Also I am a differential geometry enthusiast so the jokes are on me...
To begin first we look at the distances on the surfaces of any sphere: as a reminder for the coordinates we have: r ≥ 0, 0 ≤ θ ≤ π and 0 ≤ φ < 2π. (θ == latitude, φ == longitude) now since our displacement ds, is confined to the surface, we have dr == 0. Also we can consider a disc of distance ds away from the point a = [r, 0, 0]
These points must then satisfy ds == r dθ, which gives b = [r, ds/r, 0]. this is easy because it doesn't matter what φ actually is, it can go from 0 to 2π and this distance will remain the same, so any point b = [r, ds/r, φ] is sitting on the disc of coordinates that we are looking for.
So what if we start with a = [r, θ, φ] you may ask, to which i say, then why not convert back to a = [r, 0, 0] by adding transformation vector t = [0, -θ, -φ] calculate the coordinates for the disc, then do subtract the same transformation vector on each point (b) that you find. may the force be with you
Upvotes: 0
Reputation: 2979
You say convert to WGS84 but from what?
Look at something like http://www.gdal.org/ or http://dotspatial.codeplex.com/ (or spatial support in your DB if you're using one).
This answer over on GIS will help explain WGS84 / EPSG:4326
https://gis.stackexchange.com/questions/23690/is-wgs84-itself-a-coordinate-reference-system
and this will help when your circle turns into a ellipse :)
Upvotes: 1