1

Based on the user's location I want to draw a circle that passes a given coordinate X (so the radius will be the distance from the user location to X).

Based on this https://smilebasicsource.com/forum?fpid=7022

I managed to get a solution that works, but when I check the points I get a ellipse and not a circle.

Can anyone tell me why?

//The following code rotates with 1 degree each time its run. after 360 times I get the circle (ellipse) below.

var R = 0.0174533; //1 degree
var X = World.obj.locations[0].longitude;
var Y = World.obj.locations[0].latitude;
var CX =  World.userLocation.lon;
var CY =  World.userLocation.lat;


var C = Math.cos(R);
var S = Math.sin(R);

var DX = X - CX;
var DY = Y - CY;

var NX = CX+DX*C-DY*S;
var NY = CY+DX*S+DY*C;

World.obj.locations[0].latitude = NY;
World.obj.locations[0].longitude = NX;

google map with generated points

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
gizpanz
  • 11
  • 1
  • 2
  • Welcome to GIS SE! As a new user be sure to take the [Tour] to learn about our focussed Q&A format. You appear to have created two accounts which inevitably leads to a frustrating experience for you, potential answerers and reviewers so please follow these instructions ASAP to merge your accounts. – PolyGeo Aug 12 '16 at 05:36

1 Answers1

1

You are calculating the circle points with longitude and latitude. This will work near the equator only. Closer to the poles, the length of one degree of longitude decreases down to zero.

You should better do the same in meters, e.g. the Google Mercator projection that your basemap is projected in.

As a workaround, you could multiply the longitudes X and CX with the cosinus of latitude, and divide NX by it to get back to real longitudes, as mentioned here: Calculating longitude length in miles?

AndreJ
  • 76,698
  • 5
  • 86
  • 162
  • Web Mercator is terribly distorted. Using a local projected coordinate system, even UTM, will be better, but not perfect. – mkennedy Aug 11 '16 at 19:16
  • @mkennedy I know that, but sticking to the basemaps CRS isn't a bad idea. – AndreJ Aug 12 '16 at 05:33
  • hmm do you have some hints in the right directions about how this can be implemented (what do I need to change)? The two points will never be far from each other. We are talking 10-200 meter in range. So I would think the distortion would not be that bad or? –  Aug 11 '16 at 19:58
  • @user80643 See my extended answer. – AndreJ Aug 12 '16 at 05:38